About Question enthuware.ocpjp.v8.2.1847 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Ad9999
Posts: 15
Joined: Fri May 15, 2015 12:06 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1847 :

Post by Ad9999 »

So basically if you wanted Collectors.toMap to ignore duplicate key entries you'd pass in something like (a,b) -> a for the BinaryOperator argument.

sreeharshitha
Posts: 4
Joined: Wed Jul 10, 2019 11:41 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1847 :

Post by sreeharshitha »

as both collect and forEach are terminal operations, doesn't the code result in compilation error?

admin
Site Admin
Posts: 10404
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1847 :

Post by admin »

The code is not calling two terminal operations on the same stream. The call to collect returns a Map and forEach is called on that Map.
You might want to try compiling and running the code.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests