[Java] Primitive Stream

public class Code {
  public static void main(String[] args) {
    IntStreams.range(1,4)
          .forEach(System.out::println); // 1 2 3
    
    Arrays.stream(new int[] {1,2,3,4})
          .map(n -> n * n)
          .average()
          .ifPresent(System.out::println); // 7.5
    
    Stream.of(1.5,2.3, 3.7)
          .mapToInt(Double::intValue)
           .forEach(System.out::println); // 1 2 3
  }
}

 

posted @ 2020-12-30 03:47  Zhentiw  阅读(73)  评论(0编辑  收藏  举报