JAVA-Stream

最简单的例子:
List<String> list = Stream.of("aaa", "bbb", "ccc").map(item -> item + "xx").collect(Collectors.toList());
System.out.println(list);

常见的操作可以归类如下。

  • Intermediate:

map (mapToInt, flatMap 等)、 filter、 distinct、 sorted、 peek、 limit、 skip、 parallel、 sequential、 unordered

  • Terminal:

forEach、 forEachOrdered、 toArray、 reduce、 collect、 min、 max、 count、 anyMatch、 allMatch、 noneMatch、 findFirst、 findAny、 iterator

  • Short-circuiting:

anyMatch、 allMatch、 noneMatch、 findFirst、 findAny、 limit

参考

https://www.ibm.com/developerworks/cn/java/j-lo-java8streamapi/

猜你喜欢

转载自www.cnblogs.com/ENU7/p/9685207.html