jdk1.8新特性stream流相關api

1.map():stuList.stream().map(Student :: getScore)  拿到所有的分數

2.filter()::stuList.stream().filter(s -> s.getScore()>=90) 拿到成績大於90分的

3.sorted():分別對list和map排序(不調用reversed()方法默認升序)

       stuList.stream().sorted(Comparator.comparing(Student :: getScore).reversed() 對list中student對象中的score進行降序排

       productMap.entrySet().stream().sorted(Entry.<String, Integer>comparingByValue().reversed()) 按map中的value進行降序

4.limit():sortMap.entrySet().stream().limit(5)  取map中的前5條

5.collect():可轉list、map集合,例如:.collect(Collectors.toList())

6.reduce():主要計算總和或者最大最小值的

            

7.計算總和平均值、隨機生成範圍:

             

8.forEach():遍歷

9.Stream<String> stream = Stream.of(array) 將數組轉換成stream流

10.skip():跳過前幾個,如果希望跳過前幾個元素,可以使用skip 方法獲取一個截取之後的新流

            
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章