ProgrammingVery hardProduct-company placement · Java

What is printed?

What is printed?
Map<Boolean, List<Integer>> m = Stream.of(2, 4)
    .collect(Collectors.partitioningBy(x -> x > 5));
System.out.print(m.size() + " " + m.get(true));
  1. A. 1 null
  2. B. 2 []
  3. C. 1 []
  4. D. 2 null

Correct answer: B. 2 []

partitioningBy always produces both keys, true and false, even if one partition is empty; here true maps to an empty list. (groupingBy would have only the false key.)

More OOP with C++ and Java questions

Exams that ask this topic