Java’s Stream API

Tech Britt
1 min readOct 16, 2020

An Interface introduced in Java 8, contributed to declarative programming in Java. Declarative programming is a style of programming that describes what you want, instead of telling the compiler how to do it, which is Imperative programming. A Stream is a sequence of elements supporting sequential and parallel aggregate operations. In other words, it allows us to define a pipeline of operations to process a sequence of elements.

The stream pipeline starts off with a source that can be an array, a collection, an I/O channel, etc. Attached to that source is anywhere from none to multiple intermediate operations, and finally a terminal operation, which produces a result. Streams are lazy and computation only takes place once the terminal operation is initiated.

Below I’ll demonstrate some functionality that the Java Stream API offers.

The Object we’ll be using to demonstrate functionality:

Along with the Enum used to describe the type of Pet:

Now onto the demonstration:

--

--