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 ?
About Question enthuware.ocpjp.v8.2.2022 :
Moderators: Site Manager, fjwalraven
-
- Posts: 7
- Joined: Wed Jun 06, 2018 6:46 am
- Contact:
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2022 :
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Tue Jul 10, 2018 7:23 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2022 :
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
- Attachments
-
- Снимок экрана 2018-07-18 в 15.15.39.png (124.33 KiB) Viewed 3971 times
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2022 :
You are right. Fixed.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sun Mar 04, 2018 1:09 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2022 :
Hello,
not fixed, the result still showing 12 when should be 0.
try to fixed.
thank you,
Stefan
not fixed, the result still showing 12 when should be 0.
try to fixed.
thank you,
Stefan
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.2022 :
Fixed for sure now!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 46 guests