exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 36 discussion

Actual exam question from Oracle's 1z0-809
Question #: 36
Topic #: 1
[All 1z0-809 Questions]

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?

  • A. 2 : 30
  • B. 4 : 0
  • C. 4 : 60
  • D. 4 : 60 2 : 30 3 : 20 1 : 10
  • E. The program prints nothing.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
rameasy
Highly Voted 3 years, 12 months ago
When the ArrayList is used instead of Arrays.asList. The result is 4 : 70.
upvoted 8 times
...
steefaand
Most Recent 5 months, 4 weeks ago
There is no correct answer. Arrays.asList doesn't allow adding of new elements. If that was corrected answer would be 4 : 70. Tested both cases.
upvoted 1 times
...
r1muka5
1 year, 5 months ago
Fixing compilation errors and using new ArrayList() would result in 4:70
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Sorry 4 : 70 is error. The answer is java.lang.UnsupportedOperationException. Becource Arrays.asList() is not java.util.ArrayList, you should add List<> newList = new ArrayList<>(products); newList.add(p); So output is 4 : 70 .
upvoted 2 times
...
WilsonKKerll
2 years, 4 months ago
Answer is 4:70......
upvoted 1 times
...
Svetleto13
3 years, 2 months ago
If you change the code like that: List<Product> products = new ArrayList<>(Arrays.asList(new Product(1, 10), new Product (2, 20), new Product (2, 30))); answer is C 4:60
upvoted 2 times
...
adnano1234
4 years, 6 months ago
Arrays.asList return a Arrays type. It has fix-sized array so not support add operation. It return an UnSupportedOpertationException
upvoted 3 times
...
Destroyer
4 years, 7 months ago
Arrays.asList return a Arrays type. It has fix-sized array so not support add operation. It return an UnSupportedOpertationException
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago