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
See IntSummaryStatistics.getMax() and IntSummaryStatistics.getMin() docs, this exact behaviour is described there, when no values are recorded.
It is just sensible to return these in these corner cases.
I will just explain this behaviour IntSummaryStatistics.getMin()
here.
Example: Let us just say the list contains at least one entry. Whatever the integer value is for that entry, it is not going to be greater than Integer.MAX_VALUE
. So returning this value when there are no entries makes sense, to give an insight to the user.
Same goes for IntSummaryStatistics.getMax()