最具挑战性的挑战莫过于提升自我。——迈克尔·F·斯特利
Java9
和Java16
中更新了Stream
中的函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
List<Integer> collect = Stream.iterate(0, i -> i < 100, i -> ++i).toList(); System.out.println("iterate&toList:" + collect);
System.out.print("takeWhile:"); collect.parallelStream().takeWhile(i -> i < 66).forEach(obj -> System.out.print(obj + " ")); System.out.println();
List<Integer> drop = collect.parallelStream().dropWhile(i -> i < 66).toList(); System.out.println("dropWhile" + drop);
Stream.ofNullable(null); Stream.of("");
Stream.of("1", "2").mapMulti((a, b) -> b.accept(a + "0")).forEach(System.out::print); System.out.println();
Stream.of(1, 2).mapMultiToInt((a, b) -> b.accept(a + 1)).forEach(System.out::print); System.out.println();
Stream.of("1", "2").mapMultiToLong((a, b) -> b.accept(8L)).forEach(System.out::print); System.out.println();
Stream.of(1, 2).mapMultiToDouble((a, b) -> b.accept(a - 1)).forEach(obj -> System.out.print(obj + " "));
|
控制台打印结果