About Question enthuware.ocpjp.v8.2.1891 :

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

Moderator: admin

Post Reply
in2xes
Posts: 6
Joined: Tue Oct 20, 2015 9:47 am
Contact:

About Question enthuware.ocpjp.v8.2.1891 :

Post by in2xes »

4. System.out.println(names.stream().collect(Collectors.mapping(x->x, Collectors.summarizingInt(x->x))).getSum());

5. System.out.println(names.stream().collect(Collectors.summarizingInt(x->x)).getSum());
both options does not even compile. so answer is 2.

Or change 4 and 5 to
System.out.println(names.stream().collect(Collectors.summarizingInt(x->Integer.valueOf(x.toString()))).getSum());
System.out.println(names.stream().collect(Collectors.mapping(x->x, Collectors.summarizingInt(x->Integer.valueOf(x.toString())))).getSum());

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

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

Post by admin »

Not sure why you think it will not compile. I just compiled the code and ran it. It worked as expected:

Code: Select all

import java.util.*;
import java.util.stream.*;
public class TestClass {
  public static void main(String[] args) {
    List<Integer> names = Arrays.asList(1, 2, 3);

    System.out.println(names.stream().mapToInt(x->x).sum());

    System.out.println(names.stream().reduce(0, (a, b)->a+b));

    System.out.println(names.stream().collect(Collectors.mapping(x->x, Collectors.summarizingInt(x->x))).getSum());

    System.out.println(names.stream().collect(Collectors.summarizingInt(x->x)).getSum());

 }

}
It prints 6 four times.
If you like our products and services, please help us by posting your review here.

in2xes
Posts: 6
Joined: Tue Oct 20, 2015 9:47 am
Contact:

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

Post by in2xes »

Sorry. One of the option is working but not other. I'm yet to figure out the root cause. See attached image for compilation failure.

Image

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

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

Post by admin »

Can't comment on messages shown by an IDE. Try the command line.
If you like our products and services, please help us by posting your review here.

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

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

Post by ramy6_1 »

Hello ,

At Oracle exam topics section 4.6 , it mentioned averagingDouble(), groupingBy(), joining(), and partitioningBy() from Collector class.
Does that mean other functions also included at exam I.e Collectors.summarizingInt ?

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

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

Post by admin »

Yes, you should know about summarizingInt also. It is quite simple though.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

henrid
Posts: 31
Joined: Sun Oct 13, 2013 1:20 pm
Contact:

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

Post by henrid »

It is ridiculous having to memorize the whole API. That is NOT simple. But okay, you guys didn't create the exam.

Post Reply

Who is online

Users browsing this forum: No registered users and 84 guests