Java OCA OCP Practice Question 1725

Question

Fill in the blank so this code prints 8.0. Note that it must not print OptionalDouble[8.0].

LongStream stream = LongStream.of(6, 10);
LongSummaryStatistics stats = stream.summaryStatistics();
System.out.println(___);
  • A. stats.avg()
  • B. stats.average()
  • C. stats.average().get()
  • D. stats.getAverage()


D.

Note

The summary statistics classes provide getters in order to access the data.

The getAverage() method returns a double and not an OptionalDouble.

Option D is the only option to compile.




PreviousNext

Related