Example usage for java.util.stream LongStream reduce

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

Introduction

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

Prototype

OptionalLong reduce(LongBinaryOperator op);

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, 3L, 4L);

    OptionalLong v = b.reduce(Long::sum);
    if (v.isPresent()) {
        System.out.println(v.getAsLong());
    } else {/*from www .  j  av a2 s. c  o m*/
        System.out.println("no value");
    }

}