Given:
public class product {
int id; int price;
public Product (int id, int price) {
this.id = id;
this.price = price;
}
public String toString() { return id + ":" + price; }
}
and the code fragment:
List<Product> products = Arrays.asList(new Product(1, 10), new Product (2, 30), new Product (2, 30));
Product p = products.stream().reduce(new Product (4, 0), (p1, p2) -> { p1.price+=p2.price; return new Product (p1.id, p1.price);}); products.add(p); products.stream().parallel()
.reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
.ifPresent(System.out: :println);
What is the result?
rameasy
Highly Voted 3 years, 12 months agosteefaand
Most Recent 5 months, 4 weeks agor1muka5
1 year, 5 months agoWilsonKKerll
2 years, 4 months agoWilsonKKerll
2 years, 4 months agoSvetleto13
3 years, 2 months agoadnano1234
4 years, 6 months agoDestroyer
4 years, 7 months ago