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

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:

主站蜘蛛池模板: 新竹县| 张北县| 广平县| 张家界市| 泸定县| 大田县| 潮州市| 临海市| 拉孜县| 福泉市| 饶平县| 民丰县| 乌鲁木齐县| 淅川县| 松溪县| 龙陵县| 新巴尔虎右旗| 丹棱县| 思茅市| 仁布县| 临泉县| 霞浦县| 舒城县| 景洪市| 迭部县| 彝良县| 南宫市| 达州市| 兴城市| 富阳市| 江华| 吴旗县| 怀柔区| 济南市| 平舆县| 佳木斯市| 迁安市| 太白县| 盐边县| 旬阳县| 肃宁县|