About Question enthuware.ocpjp.v8.2.1810 :
Posted: Wed May 24, 2017 8:27 pm
List<Person> friends = Arrays.asList(new Person("Bob", 31), new Person("Paul", 32), new Person("John", 33));
double averageAge = friends.stream().filter(f->f.getAge()<30)
.mapToInt(f->f.getAge()).average().getAsDouble();
System.out.println(averageAge);
As per the logic, "average()" method returns OptionalDouble and if it is empty then getAsDouble throws an exception. Though the explanation correctly explains this but the answer selected in the test is incorrect. It still shows 0.0 as the correct answer.
Any comments?
double averageAge = friends.stream().filter(f->f.getAge()<30)
.mapToInt(f->f.getAge()).average().getAsDouble();
System.out.println(averageAge);
As per the logic, "average()" method returns OptionalDouble and if it is empty then getAsDouble throws an exception. Though the explanation correctly explains this but the answer selected in the test is incorrect. It still shows 0.0 as the correct answer.
Any comments?