Oracle
1Z0-819 · Question #65
1Z0-819 Question #65: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-819 to reveal the answer and full explanation for question #65. The question stem and answer options stay visible for context.
Question
Given
import java.util.List;
import java.util.function.BinaryOperator;
public class Main {
public static void main(String... args) {
List<Employee> list = List.of(new Employee("John", 80000.0), new Employee("Scott",
90000.0));
double starts = 0.0;
double ratio = 1.0;
BinaryOperator<Double> bo = (a, b) -> a + b;
double totalSalary = list.stream().map(e -> e.getSalary() * ratio).reduce(starts, bo); // line 1
System.out.println("Total salary = " + totalSalary);
}
}
class Employee {
String name;
double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public String getName() { return name; }
public double getSalary() { return salary; }
}
Which statement is equivalent to line 1?
Options
- Adouble totalSalary = list.stream().map(e -> e.getSalary() * ratio).reduce(bo).ifPresent(p -> p. doubleValue());
- Bdouble totalSalary = list.stream().mapToDouble(e -> e.getSalary() * ratio).sum();
- Cdouble totalSalary = list.stream().mapToDouble(e -> e.getSalary() * ratio).reduce(0.0,bo).orElse(0.0);
- Ddouble totalSalary = list.stream().mapToDouble(e -> e.getSalary() * ratio).reduce(starts, bo);
Unlock 1Z0-819 to see the answer
You've previewed enough free 1Z0-819 questions. Unlock 1Z0-819 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.