Why summaryStatistics() method on an empty IntStream returns max and min value of integer as the maximum and minimum int value present in the stream?
IntStream
This behavior is documented in the Javadoc, so that's the correct behavior by definition:
int java.util.IntSummaryStatistics.getMin()
Returns the minimum value recorded, or Integer.MAX_VALUE if no values have been recorded.
Returns:
the minimum value, or Integer.MAX_VALUE if none
and
int java.util.IntSummaryStatistics.getMax()
Returns the maximum value recorded, or Integer.MIN_VALUE if no values have been recorded.
Returns:
the maximum value, or Integer.MIN_VALUE if none
As to "what's the point of returning these values", we can argue that the minimum value of an empty Stream
should be such that if the Stream
had any element, that element would be smaller than that value.
Similarly, we can argue that the maximum value of an empty Stream
should be such that if the Stream
had any element, that element would be larger than that value.