Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Confused options regarding groupingBy() method in real exam

 
Ranch Hand
Posts: 219
27
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
In real exam I came across question regarding groupingBy() method and was asked the output. There were four options and I removed two wrong options. There were only two correct options which the output were same but the reverse order.

It is comfortable for me to ask my question using the following Enthuware question:


Given:

What will the following code print?


A. C# C#
    OCAJP Java, OCPJP Java, OCEJPA Java
B. [C# C#]
    [OCAJP Java, OCPJP Java, OCEJPA Java]
C. [C#]
    [OCAJP OCPJP OCEJPA]
D. C#
    OCAJP OCPJP OCEJPA

The correct answer is B in this question.
Now you can imagine that there are only two options:

E. [OCAJP Java, OCPJP Java, OCEJPA Java]
    [C# C#]
F. [C# C#]
    [OCAJP Java, OCPJP Java, OCEJPA Java]

Is there any rule to determine the output order? Is output order predictable in advance in this question? Isn't weird to giving these options together at the same time?
 
Master Rancher
Posts: 3396
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There does not appear to be any documented rule for this, and based on limited testing on my part, the results are much like you'd get from a hashmap, which is to say they are in a somewhat random unpredictable order.   The only way I can see a question like this being fair and valid, is if they ask which outputs are possible, and then the correct answer is that both E and F are possible.  So either you've misremembered or misinterpreted the question, or it's unfair and wrong.
 
Bartender
Posts: 3590
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not unfair. The number of correct answers is always mentioned.

But there are ways to determine the outcome. Look at the API of Collectors.groupingBy. You will see that you can specify what Map is created (TreeMap, for instance) and what kind of Collection to use for the values (List, or Set, or ...)
 
Mike Simmons
Master Rancher
Posts: 3396
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, so if the question did use a version of groupingBy different from what was shown here, that would be fair.
 
Piet Souris
Bartender
Posts: 3590
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway, the biggest hurdle of this exercise is to realize that B is the correct answer, and not C. Took me a minute of staring... so if OP got that right, then he has nothing to worry.
 
Enthuware Software Support
Posts: 4354
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:Anyway, the biggest hurdle of this exercise is to realize that B is the correct answer, and not C. Took me a minute of staring... so if OP got that right, then he has nothing to worry.


The issue is not with the question posted above by Mushfiq. He is using it as a base to explain the issue that he faced in the exam. What if the question had these options instead of the existing options?


E. [OCAJP Java, OCPJP Java, OCEJPA Java]
   [C# C#]
F. [C# C#]
   [OCAJP Java, OCPJP Java, OCEJPA Java]



How would you decide which one is correct?

The answer is same as explained above by you and Mike. Either the candidate is missing a clue in the problem statement (most likely) or the question is unfair/wrong (less likely).
 
Mushfiq Mammadov
Ranch Hand
Posts: 219
27
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was required only one option. When I saw E and F (for example) options I thought this is ambiguous. Therefore I looked at question again and looked for compile error or exception probability. But I remember (~80%) that there were no such options, all options contained output. Maybe I missed any tricky point but after review I saw again that correct option should be option E or F.
I learn that groupingBy created HashMap as a result in most cases and the order of elements are unspecified.

Finally I chose option E.. According to exam score report I think it was wrong. It is interesting that option F was correct answer or not.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!