Java IntSummaryStatistics getMax()方法及示例
Java中IntSummaryStatistics类 的 getMax() 方法用于获取该IntSummaryStatistics中记录的最大值。
语法。
public int getMax()
参数。此方法不接受任何值作为参数。
返回值。该方法返回该IntSummaryStatistics中的最大记录。
程序。
// Java program to demonstrate
// the above method
import java.util.*;
public class IntSummaryStatisticsDemo {
public static void main(String[] args)
{
IntSummaryStatistics intSummaryStatistics
= new IntSummaryStatistics();
List<Integer> list
= Arrays.asList(10, 20, 30, 40, 50);
Iterator<Integer> iterator = list.listIterator();
while (iterator.hasNext()) {
// Add the integers to the IntSummaryStatistics object
intSummaryStatistics.accept(iterator.next());
}
System.out.println("The maximum of values is "
+ intSummaryStatistics.getMax());
}
}
输出。
The maximum of values is 50
**参考资料: ** https://docs.oracle.com/javase/10/docs/api/java/util/IntSummaryStatistics.html#getMax()