I have the following class:
public class Transfer {
private String fromAccountID;
private String toAccountID;
private double amount;
}
and a List of Transfers:
....
private List<Transfer> transfers = new ArrayList<>();
I know how to get one transfer history:
transfers.stream().filter(transfer ->
transfer.getFromAccountID().equals(id)).findFirst().get();
But I want to get by fromAccountID and toAccountID, so the result will be a List of Transfers. How can I do that with Java8 Stream filter functions?
get()straight from an optional result except in cases where you know there will be a value present. rather you should utiliseorElseororElseGetdepending on which is most appropriate for your case