r/learnjava • u/BananaPunsch • Mar 30 '20
Java Lambda expressions
I am a little lost as to what they are, how they work or what I can use them for.
I have no real example, just stumbled across the term and would like to understand it.
Are there understandable easy examples?
Thanks for possible help.
Edit: I found a pretty good explanation here. I just needed a easy and small example to wrap my head around this. Thanks to everyone who tried to help.
41
Upvotes
0
u/RexStardust Mar 30 '20
Here's an example from a little side project:
List <Transaction> returnDetailList = transactionArray.stream() .filter(x -> (x.getStatustext().equals(transactionType))) .filter(x -> (x.getTransactionCompleteTime().toLocalDate().isAfter(transactionRange.getAfterStartDate()))) .filter(x -> (x.getTransactionCompleteTime().toLocalDate().isBefore(transactionRange.getBeforeEndDate()))) .collect(Collectors.toList());This takes an array of Transaction objects (Blue Prism robotics), filters by transaction type (completed or exception), then further filters to select transactions in the given date range. The output of the stream is a List of Transaction objects.