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

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.
主站蜘蛛池模板: 当雄县| 长海县| 浮梁县| 大埔区| 正宁县| 静乐县| 鸡西市| 兴隆县| 敦煌市| 浠水县| 怀安县| 芷江| 永川市| 龙岩市| 抚顺市| 遵义市| 闽清县| 开远市| 资溪县| 千阳县| 双鸭山市| 柏乡县| 县级市| 涞源县| 黑水县| 固始县| 保亭| 三亚市| 织金县| 凌源市| 慈利县| 福泉市| 南和县| 玉山县| 鄢陵县| 西林县| 喜德县| 雷波县| 洛扎县| 长顺县| 盖州市|