- Apache Spark 2.x for Java Developers
- Sourav Gulati Sumit Kumar
- 274字
- 2021-07-02 19:01:57
Streams
A stream represents a collection of elements on which a chain of aggregate operations can be performed lazily. Streams have been optimized to cater to both sequential as well as parallel computation, keeping in mind the hardware capabilities of CPU cores. The Steams API was introduced in Java 8 to cater to functional programming needs of the developer. Streams are not Java based collections; however, they are capable enough to operate over collections by first converting them into streams. Some of the characteristics of streams that make them uniquely different from Java collection APIs are:
- Streams do not store elements. It only transfer values received from sources such as I/O channels, generating functions, data structures (Collections API), and perform a set of pipelined computation on them.
- Streams do not change the underlying data, they only process them and produce a new set of resultant data. When a distinct() or sorted() method is called on a stream, the source data does not change, but produces a result that is distinct or sorted.
- In general, streams are lazily evaluated; this leaves plenty of opportunity for code optimization. The thumb rule for lazy evaluation being that if an operation returns a stream then it is lazy or otherwise eager.
- Unlike collections streams, can be unbounded. This critically serves the purpose of processing streaming data in particular. Unbounded streams can be interrupted using the methods limit(), findFirst(), and so on.
- Streams are consumable, which means once a terminal operation gets fired on a stream it cannot be reused again. A similar parlance can be drawn from an iterator, which once iterated over needs to be regenerated again.
推薦閱讀
- Learning Neo4j
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- Mastering Entity Framework Core 2.0
- 機器學(xué)習(xí)系統(tǒng):設(shè)計和實現(xiàn)
- 自制編譯器
- Visual C++數(shù)字圖像模式識別技術(shù)詳解
- Wireshark Network Security
- Mastering LibGDX Game Development
- FFmpeg入門詳解:音視頻原理及應(yīng)用
- Learning ArcGIS for Desktop
- Mastering openFrameworks:Creative Coding Demystified
- 硬件產(chǎn)品設(shè)計與開發(fā):從原型到交付
- Hacking Android
- Clojure編程樂趣
- 從零開始學(xué)UI設(shè)計·基礎(chǔ)篇