Home  >  Article  >  Java  >  Simple example of IntSummaryStatistics in Java

Simple example of IntSummaryStatistics in Java

黄舟
黄舟Original
2017-01-17 15:19:511871browse

Ask a question

How to use Java's IntSummaryStatistics class simply? ? ?

Solve the problem

This class is mainly used in conjunction with the stream class. In the java.util package, it is mainly used to count the maximum value, minimum value, and average value of the elements in the integer array. Number, sum of elements, etc. The following is a simple example:

[code]package com.evada.de;
import java.util.IntSummaryStatistics;
import java.util.stream.IntStream;

/**
 * Created by Ay on 2016/5/24.
 */
public class LambdaTest {

    public static void main(String[] args) {
        int[] intArray = {12,3,34,67,100,99};
        /** 第一种构造intStream **/
        IntStream intStream = IntStream.of(intArray);
        /** 第二种构造intStream **/
        //IntStream intStream2 = IntStream.of(12,3,34,67,100,99);
        /** 这个是重点,获得当前int数组的统计信息,包括 **/
        IntSummaryStatistics statistics = intStream.summaryStatistics();
        /** 计算出最大,最小,平均等等,是不是很好用,赶紧get起来 **/
        System.out.println("the max:" + statistics.getMax());
        System.out.println("the min:" + statistics.getMin());
        System.out.println("the average:" + statistics.getAverage());
        System.out.println("the sum:" + statistics.getSum());
        System.out.println("the count:" + statistics.getCount());

    }
}

The above is the content of a simple example of IntSummaryStatistics in Java. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn