Java 8 - API Enhancements to Take Advantage of Lambda

[Updated: Sep 27, 2016, Created: Dec 15, 2015]

In Java SE 8, new classes have been added and existing classes have been enhanced to take advantage of lambda expressions and streams. Many new default methods were added on collection interfaces as enhancement. Mainly aggregate operations over collections are provided in a declarative manner rather than imperative manner. Declarative programming focuses on what the program should accomplish without specifying how the program should achieve the result. In other words we describe in what results we are interested without explicitly listing commands or steps that must be performed. Most of the API changes involves taking advantage of internal iterator by using Lambda expression. The internal iterator, is kind of iterator where the library takes care of iteration rather than client code has to do iteration itself (external iterator).

New package

Classes to support functional-style operations on streams of elements, such as map-reduce transformations on collections. Please visit our Java 8 Stream API tutorials.

Streams are lazy; computation on the source data is only performed when the terminal operation is initiated, and source elements are consumed only as needed.

Streams can be sequential or parallel. We can explicitly switch to stream.sequential() or stream.parallel(). A sequential stream occur in serial manner. A parallel stream may be happening all at once utilizing multiple cores of the machine. Here's a comparison between the two.

See Also