
LinkedList<String> temp=RawDataList.time_List.stream() |
.map(e->(Tools.getMonthFromDate(e))) //map()是对stream中每个元素都进行操作 |
.collect(Collectors.toCollection(LinkedList::new)); //将stream转换为其他的数据结构 |
清单 1. 流转换为其它数据结构 |
// 1. Array |
String[] strArray1 = stream.toArray(String[]::new); |
// 2. Collection |
List<String> list1 = stream.collect(Collectors.toList()); |
List<String> list2 = stream.collect(Collectors.toCollection(ArrayList::new)); |
Set set1 = stream.collect(Collectors.toSet()); |
Stack stack1 = stream.collect(Collectors.toCollection(Stack::new)); |
// 3. String |
String str = stream.collect(Collectors.joining()).toString(); |
目前Stream还缺少一个操作,就是分类处理,针对不同类型的数据,执行不同的逻辑 |




by: 发表于:2017-07-17 16:46:40 顶(0) | 踩(0) 回复
??
回复评论