创建Stream

方式 方法 示例
由值创建流 Stream.of Stream stream = Stream.of("Java 8 ","Lambdas ", "In ", "Action"); stream.map(String::toUpperCase).forEach(System.out::println);
由数组创建流 Arrays.stream int[] numbers = {2, 3, 5, 7, 11, 13}; int sum = Arrays.stream(numbers).sum(); (值为41)
由文件生成流 Files.lines Stream lines = Files.lines(Paths.get("/Users/user/Downloads/2019-04-18.csv")
创建无限流 Stream.iterate、 Stream.generate Stream.iterate(0, n -> n + 2).limit(10) .forEach(System.out::println);Stream.generate(Math::random) .limit(5).forEach(System.out::println);

你可能感兴趣的:(java)