What is the best way to maintain a list of Transactions (transaction object having fields like id, date, amount etc) so that i can fetch results based on different criteria like
You can use the Java 8 Stream API.
Say transactions
is a List<Transaction>
, you can use, for example:
List<Transaction> validTrxs = transactions.stream()
.filter( (Transaction tr) -> tr.isValid() )
.collect( Collectors.toList() );
(Instead of tr.isValid()
you could put practically any condition you can make into a boolean
expression)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.