Page 1 of 1
About Question enthuware.ocpjp.v8.2.2022 :
Posted: Tue Jul 17, 2018 3:50 am
by d0wnvk@gmail.com
IntStream is2 = IntStream.of(2, 4, 6); //4
int y = is2.filter( i->i%2 != 0 ).sum(); //5
System.out.println(y); //6
is line //5 really returns 12 ?
I mean 4%2 == 0, which means
filter( i->4%2 != 0 ) returns false.
Where is I am wrong ?
Re: About Question enthuware.ocpjp.v8.2.2022 :
Posted: Tue Jul 17, 2018 5:15 am
by admin
An element will be removed from the stream if the condition is true. If i%2 is 0 then the condition is not true and so element will NOT be removed.
Re: About Question enthuware.ocpjp.v8.2.2022 :
Posted: Wed Jul 18, 2018 7:22 am
by evgeny.kruptsov
Please fix the explanation, result is 0 for the following snippet of code:
Code: Select all
IntStream is2 = IntStream.of(2, 4, 6); //4
int y = is2.filter( i->i%2 != 0 ).sum(); //5
System.out.println(y); //6
Re: About Question enthuware.ocpjp.v8.2.2022 :
Posted: Wed Jul 18, 2018 10:10 am
by admin
You are right. Fixed.
thank you for your feedback!
Re: About Question enthuware.ocpjp.v8.2.2022 :
Posted: Tue Sep 25, 2018 8:56 pm
by stefanbanu
Hello,
not fixed, the result still showing 12 when should be 0.
try to fixed.
thank you,
Stefan
Re: About Question enthuware.ocpjp.v8.2.2022 :
Posted: Tue Sep 25, 2018 10:31 pm
by admin
Fixed for sure now!