There is a simple query that filters a list and gets a field value of the item found.
myList.getParents().stream()
.filter(x -> x.getSomeField() == 1)
.map(x -> x.getOtherField())
.findFirst();
Are operations executed one after one as in code: from initial list we filter all where someField
is 1, after it we create new list with a value of another field and after it we take the first one in this new list?
Let's imagine that there are 1 000 000 items in this list and after filtering they are 1000. Will it map those 1000 items to get only first one of them?
If I change the order will it optimize the performance or is it smart enough itself?
myList.getParents().stream()
.filter(x -> x.getSomeField() == 1)
.findFirst()
.map(x -> x.getOtherField());