summaryStatistics Method of IntSummaryStatistics

前端 未结 4 1995
轮回少年
轮回少年 2021-01-23 17:27

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          


        
4条回答
  •  萌比男神i
    2021-01-23 17:40

    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()

提交回复
热议问题