Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Sun Nov 15, 2020 7:07 am
by mario236
Hi. Question from mocks for 1z0-817.

Given:
List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13, 17); //1
Stream<Integer> primeStream = primes.stream(); //2
Predicate<Integer> test1 = k->k<10; //3
long count1 = primeStream.filter(test1).count(); //4
Predicate<Integer> test2 = k->k>10; //5
long count2 = primeStream.filter(test2).count(); //6
System.out.println(count1+" "+count2); //7 Identify correct statements.


And the answer marked as the correct one is:

It will print 34 if lines 4 to 7 are replaced with: primeStream.collect(Collectors.partitioningBy(test1, Collectors.counting()))       .values().forEach(System.out::print);

The problem in this question is attempt to reuse already terminated Stream but the correct answer seems to be doing the same. Collect is a terminal operation too.

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Sun Nov 15, 2020 11:20 am
by admin
Yes, collect is a termination operation and you can't use that stream anymore. But, in this case, the call to collect returns a Map (because are passing Collectors.partitioningBy ), and you can call the values() method on a Map.
So, the correct answer is not really invoking another operation on a terminated stream.

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Sun Nov 15, 2020 12:54 pm
by mario236
I replaced lines 4 & 7 but the intention was to replace lines from 4 to 7. Ok my mistake.

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Mon Aug 30, 2021 1:06 pm
by floryan

It will print 34 if lines 4 to 7 are replaced with: primeStream.collect(Collectors.partitioningBy(test1, Collectors.counting()))       .values().forEach(System.out::print);
Couldn't it also be 43? Is the order of "values()" guaranteed?

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Mon Aug 30, 2021 9:22 pm
by admin
Yes, it could be 43 also but that is not one of the options (neither is "None of the above") and since the best option needs to be picked, this is the right option.

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Fri Oct 08, 2021 11:50 am
by floryan
admin wrote:
Mon Aug 30, 2021 9:22 pm
Yes, it could be 43 also but that is not one of the options (neither is "None of the above") and since the best option needs to be picked, this is the right option.
To me this is not correct. It says to identify correct statements and not "the one closest to being correct". The answer "It will print 34" COULD be correct. I feel the answer should be "It could print 34" or "It will either print 34 or 43".

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Sun Oct 10, 2021 1:17 am
by admin
You are technically correct that 34 or 43, would be more precise. However, in absence of any other option, we believe this option is correct because it does actually print 34.

Regarding, "It says to identify correct statements and not "the one closest to being correct"": Again, if there were an option that said "None of the above", then I would pick that option. But that is not the case.

In the real exam also, you may find options that may have some ambiguity and you would have to select the best option. The best option is the correct option for securing points for that question. So, I would suggest you to focus on what the question is trying to get at instead of trying to find absolute precision in statement.

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Wed Oct 13, 2021 12:06 pm
by floryan
I understand your point, I just think it's weird. For some questions we need to be absolute precise and every single word needs to be considered and evalutated. And then apparently there are other questions which have a rather vague wording and answers. I feel that there should be a consistent "style" across all questions.
This is not a criticism towards you but towards the creators of the exam, if their questions are indeed like that. Obviously we/I simply have to accept it the way it is.

Re: About Question enthuware.ocpjp.ii.v11.2.1901 :

Posted: Thu Oct 14, 2021 10:14 pm
by admin
I agree but there is a pattern that they follow. Here is what we have observed:

When they are looking for precision, they provide multiple similar options. For example, in this case, had they been looking for order, they would have given two options 34, 43, and 34 or 43, in which case you would pic 34 or 43. You may even see a "None of the above" in such questions.

Otherwise, when the focus of the question is something else, the options do not go into the finer details. For example, for a question such as "what will the following code print" and options, "compiler error, some output, exception at runtime", assuming the code causes an exception, they are not focusing on whether there is a NPE or FileNotFoundException. Just "exception" and so you will need to pick that.

Finally, we always say that the question and options are created by humans. So, you cannot avoid a little bit of ambiguity here and there. So, I would say, use your judgement and pick the best option as per the situation.

All the best!