Java IntStream reduce

Description

Java IntStream reduce

import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    int[] values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0};

    IntStream intStream = IntStream.of(values);
    // sum of values with reduce method
    int r = intStream.reduce(0, (x, y) -> x + y);
    //ww w .j  ava 2 s .c o  m
    System.out.println("sum:"+r);

  }
}



PreviousNext

Related