Java SE 8 Programmer II (1Z0-809)
© examsiri.com
Question : 2 of 8
Marks:
+1,
-0
Given:
And given the code fragment:
class Toy {
double price;
String color;
Toy(String color, double price) {
this.color = color;
this.price = price;
}
public double getPrice() {
return price;
}
public String getColor() {
return color;
}
} And given the code fragment:
List toys = new ArrayList<>();
toys.add(new Toy("red", 10));
toys.add(new Toy("yellow", 10));
toys.add(new Toy("red", 10));
double totalPrice = toys.stream()
.filter(e -> e.getColor() == "red")
/* Line n1 */
.sum();
System.out.println("Total Price of Red Toys: " + totalPrice); Which code fragment can be inserted at Line n1 to enable the code to print Total Price of Red Toys: 20.0?
Go to Question: