- Apache Spark 2.x for Java Developers
- Sourav Gulati Sumit Kumar
- 159字
- 2021-07-02 19:01:59
Finding elements
Finding elements in Java streams has the following variants:
- Find any element of the stream: The method findAny() is a short circuited terminal operation where the terminal operation returns the first encountered value of the stream before exiting the operation. In the case of an empty stream an empty optional is returned. It is also a non-deterministic function and hence the execution in parallel may return different values in each execution:
System.out.println("In a paralled stream from 5-100 finding any element :: "+IntStream.range(5, 100).parallel().findAny());
- Find first elements of the stream: This is a deterministic function and it returns the first element of the stream or an empty optional in the case of an empty stream:
System.out.println("In a paralled stream from 8-100 finding the first element :: "+IntStream.range(8, 100).parallel().findFirst());
- Count: This counts the number of elements present in a stream and then returns its value as a long:
Long elementCount=streamSupplier.get().count();
System.out.println("The number of elements in the stream are:: "+elementCount);
推薦閱讀
- Magento 2 Theme Design(Second Edition)
- Learning C++ Functional Programming
- 青少年美育趣味課堂:XMind思維導(dǎo)圖制作
- Web Development with MongoDB and Node(Third Edition)
- Unity 2D Game Development Cookbook
- Mastering Business Intelligence with MicroStrategy
- R用戶Python學(xué)習(xí)指南:數(shù)據(jù)科學(xué)方法
- Python+Tableau數(shù)據(jù)可視化之美
- Node學(xué)習(xí)指南(第2版)
- 計算機應(yīng)用基礎(chǔ)教程(Windows 7+Office 2010)
- Machine Learning for Developers
- Visual Basic程序設(shè)計全程指南
- Kotlin入門與實戰(zhàn)
- C++標準庫(第2版)
- PyTorch生成對抗網(wǎng)絡(luò)編程