Example usage for java.util.stream IntStream reduce

List of usage examples for java.util.stream IntStream reduce

Introduction

In this page you can find the example usage for java.util.stream IntStream reduce.

Prototype

OptionalInt reduce(IntBinaryOperator op);

Source Link

Document

Performs a reduction on the elements of this stream, using an associative accumulation function, and returns an OptionalInt describing the reduced value, if any.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.of(6, 5, 7, 1, 2, 3, 3);
    OptionalInt v = i.reduce(Integer::sum);
    if (v.isPresent()) {
        System.out.println(v.getAsInt());
    } else {/*from w w w  . ja  v a  2 s .  c  o m*/
        System.out.println(v);
    }

}