IntStream empty = IntStream.empty();
IntStream intStream = IntStream.of(1, 2, 3);
IntStream range = IntStream.range(1, 10);
IntStream rangeClosed = IntStream.rangeClosed(1, 10);
IntStream generated = IntStream.generate(() -> 3);
IntStream infinite = IntStream.iterate(1, operand -> operand + 2);
1.filter方法
IntStream.of(1, 2, 3, 4, 5, 6, 7).filter(elem -> elem % 2 == 0).forEach(System.out::println);
2.map 方法
// 输出 10, 20, 30, 40, 50, 60, 70
IntStream.of(1, 2, 3, 4, 5, 6, 7).map(elem -> elem * 10).forEach(System.out::println);
3.mapToObj 方法
IntStream.of(1, 2, 3, 4, 5, 6, 7).mapToObj(elem -> "a" + elem).forEach(System.out::println);
4.mapToLong 方法
IntStream.of(1, 2, 3, 4, 5, 6, 7).mapToLong(elem -> elem * 100L).forEach(System.out::println);
5.mapToDouble 方法
IntStream.of(1, 2, 3, 4, 5, 6, 7).mapToDouble(elem -> elem + 0.1).forEach(System.out::println);
6.min 方法
System.out.println(IntStream.of(1, 2, 3, 4).min().getAsInt());
7.summaryStatistics 方法
IntSummaryStatistics summary = IntStream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).summaryStatistics();
System.out.println(summary.getMin());
System.out.println(summary.getMax());
System.out.println(summary.getSum());
System.out.println(summary.getCount());
System.out.println(summary.getAverage());