persons.stream()
.mapToInt(Person::getAge)
.filter(p->p<20)
.reduce(0, (a,b)->a+b);
Here the order of operations is not optimal
The main operations in a Stream pipeline and the order in which they occur are:
filter
sorted
map
collect
IntStream mapToInt(ToIntFunction<? super T> mapper)
ToIntFuncion f = (Person x) -> x.getAge();
or method reference
Person::getAge
Stream<T> filter(Predicate<T> predicate)
Predicate predicate = p->p<20
int reduce(int identity,
IntBinaryOperator op)
IntBinarytOperator<T> = (a,b) -> a+b
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
6 months, 1 week agod7bb0b2
6 months, 4 weeks agod7bb0b2
6 months, 4 weeks agod7bb0b2
7 months agoAshan_Ozlov
7 months, 1 week ago