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:
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.
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 ...)
I hate signatures!
posted 1 year ago
Yes, so if the question did use a version of groupingBy different from what was shown here, that would be fair.
posted 1 year ago
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.
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]
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).
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.