码迷,mamicode.com
首页 > 编程语言 > 详细

3-JavaSe-1-stream-1-流库特征

时间:2019-09-26 00:19:47      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:word   如何   而不是   length   count()   get   har   into   asList   

1.parallelStream可以让流库以并行方式来执行过滤和计数。

String content=new String(Files.readAllBytes(Paths.get("D:\\test\\alice.txt")), StandardCharsets.UTF_8);//read file into string
List<String> words = Arrays.asList(content.split(" "));
long count2 = words.parallelStream() //可以让流库并行的执行过滤和计数
.filter(w -> w.length() > 5).count();

2.使用流,可以说明想要完成什么任务,而不是说明如何去使用它。

3.流不会改变,总会新建(中间流转换操作)

3-JavaSe-1-stream-1-流库特征

标签:word   如何   而不是   length   count()   get   har   into   asList   

原文地址:https://www.cnblogs.com/ywdjx/p/3-JavaSe-1-stream-1.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!