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

Terminal operations

Terminal operations act as the trigger point in a pipelined stream operation to trigger execution. Terminal operations either return a void or a non-stream type object and once the pipelined operations have been executed on the stream, the stream becomes redundant. A Terminal operation is always required for a pipelined stream operation to be executed.

Stream operations can further be classified as short-circuiting operations. An intermediate operation is said to be short circuited when an infinite input produces a finite stream such as in the case of the limit() method. Similarly, short circuiting operations in the case of terminal operations is when an infinite input may terminate in finite time, as is the case for the methods anyMatch(), findAny(), and so on.

Streams also support parallelism , but in the case of stateful operations, since each parallel operation can have its own state, a parallel stateful operation may have to undergo multiple passes to complete the operation. For example, the distinct() method will not produce the correct results if the results are processed parallel in one go. However, no such restriction of multiple passes exists for stateless operations. The entire set of operations remains the same for both serial and parallel execution, only differentiator being the stream itself. If the Stream is parallel the operation will happen in parallel, or else the operations take place serially. The streams API provides a helper method, isParallel(), to check if the stream is serial or parallel. The only pre-condition that is required for a parallel stream operation to match that of the serial stream is the values passed to the operation must be non-interfering , where non-interfering is defined as the data whose underlying value does not change for any given set of operations.

The order of data in a stream can be dependent upon the source, intermediate operation, or the terminal operation.

主站蜘蛛池模板: 南充市| 阿尔山市| 和顺县| 安乡县| 漯河市| 乐平市| 津南区| 林周县| 来安县| 蒙自县| 汉川市| 鞍山市| 武定县| 明光市| 古蔺县| 伊吾县| 杨浦区| 石阡县| 阳泉市| 铅山县| 吴堡县| 阿图什市| 柯坪县| 南宁市| 施秉县| 务川| 新巴尔虎左旗| 香格里拉县| 无为县| 如皋市| 汉寿县| 内黄县| 台江县| 英德市| 荥经县| 高唐县| 鱼台县| 乌苏市| 鲁甸县| 金川县| 荆门市|