How to get the last executed transaction? I work with a Wallet app and using the BitcoinJ for programming. I need to find the last executed transaction from the wallet. In the org.bitcoinj.core.Wallet class, I see there is a method getTransactionsByTime() that returns list of all non-dead, active transactions ordered by recency as List&lt;Transaction&gt;. 

Will I access the most recent transaction with index 0 or the last index? I have made some experiments and I likely think that would be with index of 0. Because, it returns the sending info and I have done some recently, but, still weird as the amount doesn't match with performed. 

While I have tried with the last index, I think that's obviously not the case as that's returns the info of the incoming transactions. 

The way I find the most recent transaction, 

    transactions.addAll(wallet.getTransactionsByTime());    
    Transaction ts = size &gt; 0 ? getTransactions().get(0) : null;
    this.transaction = addTransactionHistory(ts);


I print the transaction as the most recent one in console.
The first transaction in the list should be the newest one.

The best way to answer such questions is always to read the source code. getTransactionsByTime calls getRecentTransactions, and there is a comment:


  Returns an list of N transactions, ordered by increasing age.


You can trace down to find the critical minus sign that ensures this.

You can also find a test that explicitly verifies it works as documented.