Teaching myself about Using Java’s Stream API

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:

Self-Taught Developer | On the journey of mastery

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store