exam questions

Exam 1z0-819 All Questions

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

Exam 1z0-819 topic 1 question 121 discussion

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

Given:



You want to calculate the average of the Player’s score.

Which statement inserted on line 1 will accomplish this?

  • A. players.stream().average().orElse(0.0);
  • B. players.stream().mapToInt(a -> a.score).average().orElse(0.0);
  • C. players.stream().mapToDouble(a -> a.score).average();
  • D. players.stream().map(a -> a.score).average();
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

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
ASPushkin
1 month, 2 weeks ago
Selected Answer: B
answer: B A. Failed there is no such method as average() in Stream B. correct IntStream OptionalDouble average() public double orElse​(double other) If a value is present, returns the value, otherwise returns other. so it returns double C. Failed Failed this expression returns OptionalDouble so double average = players.stream().mapToDouble(a -> a.score).average(); returns MyClass.java:17: error: incompatible types: OptionalDouble cannot be converted to double D. Failed there is no such method as average() in Stream
upvoted 1 times
...
d7bb0b2
6 months ago
B => to contact orElse return a double. Lonely average return a optionalDouble OTHHERS stream not contain average, InsStream or InDouble yes but with orElse clause return a primitive value
upvoted 1 times
...
Omnisumem
9 months, 1 week ago
Selected Answer: B
tested.
upvoted 1 times
...
Stavok
11 months, 3 weeks ago
Selected Answer: B
The correct statement to insert on line 1 to calculate the average of the Player's score is option B: `players.stream().mapToInt(a -> a.score).average().orElse(0.0);`. This statement uses the `mapToInt` method to convert the stream of `Player` objects into an `IntStream` of their scores, then calculates the average using the `average` method, and finally returns the result or 0.0 if no result is present using the `orElse` method.
upvoted 2 times
...
Jtic
1 year, 4 months ago
Selected Answer: B
double average = players.stream().mapToInt(a -> a.score).average().orElse(0.0);
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