java – Is it possible to get both min() and max() from one Stream at once?

Question:

Let there be an IntStream , is it possible to get an array or a sheet from it, in which there will be 2 values min and max of the stream? Or is it possible to somehow call the terminal method on the stream more than 1 time?

Answer:

IntSummaryStatistics stats = IntStream.range(1, 100)
                                      .summaryStatistics();

int min = stats.getMin();
int max = stats.getMax();
Scroll to Top