- Apache Spark 2.x for Java Developers
- Sourav Gulati Sumit Kumar
- 100字
- 2021-07-02 19:01:58
Collection collectors
The Collectors method also provides ways to reduce the stream into mutable data structures such as lists and sets:
//Collection Collectors
List<String>listCollected = streamSupplier.get().collect(Collectors.toList());
System.out.println("The list collected value of Stream are :: " + listCollected);
Set<String>setCollected=streamSupplier.get().collect(Collectors.toSet());
System.out.println("The set collected value of Stream are :: " + setCollected);
By default, the toSet() method produces a HashSet and hence the results are unsorted. If we want the results to be sorted, we can use the toCollection() method to specify an ordered set, in our case let's use Tree Set:
Set<String>orderedSetCollected=streamSupplier.get().collect(Collectors.toCollection(TreeSet::new));
System.out.println("The ordered set collected value of Stream are :: "+orderedSetCollected);
推薦閱讀
- SQL Server 從入門到項目實踐(超值版)
- Learning Selenium Testing Tools with Python
- Game Programming Using Qt Beginner's Guide
- 體驗設計原理:行為、情感和細節
- 云原生Spring實戰
- C語言程序設計上機指導與習題解答(第2版)
- 零基礎學Kotlin之Android項目開發實戰
- Django 3.0入門與實踐
- GameMaker Essentials
- WCF編程(第2版)
- IBM DB2 9.7 Advanced Application Developer Cookbook
- 人件集:人性化的軟件開發
- Python程序設計案例教程:從入門到機器學習(微課版)
- Spark Streaming技術內幕及源碼剖析
- 編寫高質量代碼:改善JavaScript程序的188個建議