... NoSuchElementException
. As withOptionalInt
, to prevent this exception, you can instead call methodorElse
, which returns theOptionalDouble
’s value if there is one, or the value you pass toorElse
, otherwise.
Class IntStream
also provides method summaryStatistics
that performs the count
, min
, max
, sum
and average
operations in one pass of an IntStream
’s elements and returns the results as an IntSummaryStatistics
object (package java.util
). This provides a significant performance boost over reprocessing an IntStream
repeatedly for each individual operation. This object has methods for obtaining each result and a toString
method that summarizes all the results. For example, the statement:
System.out.println(IntStream.of(values).summaryStatistics());
produces: ...
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.