What is the result of the following?
class Employee {/*from ww w . j ava 2 s . co m*/ private String name; private int empNum; private int score; public Employee(String name, int empNum, int score) { this.name = name; this.empNum = empNum; this.score = score; } // all getters and setters } public class Main { public static void main(String[] args) { Stream<Employee> ballots = Stream.of( new Employee("Jack", 1, 10), new Employee("Tom", 1, 8), new Employee("Jack", 2, 9), new Employee("Tom", 2, 8) ); Map<String, Integer> scores = ballots.collect( groupingBy(Employee::getName, summingInt(Employee::getScore))); // w1 System.out.println(scores.get("Jack")); } }
B.
This code compiles.
It creates a stream of Employee objects.
Then it creates a map with the contestant's name as the key and the sum of the scores as the value.
For Jack, this is 10 + 9, or 19, so Option B is correct.