官术网_书友最值得收藏!

Intermediate operations

Intermediate operations always return another stream and get lazily evaluated only when terminal operations are called. The feature of lazy evaluation optimizes intermediate operations when multiple operations are chained together as evaluation only takes place after terminal operation. Another scenario where lazy evaluation tends to be useful is in use cases of infinite or large streams as iteration over an entire stream may not be required or even possible, such as anyMatch, findFirst(), and so on. In these scenarios, short circuiting (discussed in the next section) takes place and the terminal operation exits the flow just after meeting the criteria rather than iterating over entire elements.

Intermediate operations can further be sub-divided into stateful and stateless operations. Stateful operations preserve the last seen value, as in methods such as sorted(), limit(), sequential(), and so on since they need them while processing the current record. For example, the limit() method needs to keep a check on the maximum number of elements allowed in that stream and it can only be achieved if we possess the count of records previously stored in the stream. A stateless operation has no such obligation to manage the state of stream and hence operations such as peek(), map(), filter(), and so on do not possess any state as such:

主站蜘蛛池模板: 内丘县| 颍上县| 仙游县| 陇南市| 木里| 乃东县| 阿城市| 姜堰市| 邢台市| 阜平县| 毕节市| 保靖县| 湘西| 巍山| 新津县| 泌阳县| 玛纳斯县| 报价| 商丘市| 阿克苏市| 巴东县| 定日县| 涟源市| 东源县| 苏尼特右旗| 库车县| 抚远县| 偃师市| 娄底市| 蓬莱市| 开江县| 洛隆县| 奉化市| 阿尔山市| 大足县| 孝昌县| 闽侯县| 孟津县| 永清县| 邻水| 永嘉县|