The Stream API is a new addition to the Collections API in Java 8. The Stream API brings new ways to process collections of objects. A stream represents a sequence of elements and supports different kinds of operations (filter, sort, map, and collect) from a collection. We can chain these operations together to form a pipeline to query the data, as shown in this diagram:
We can obtain a Stream from a collection using the .stream() method. For example, we have a dropdown of languages supported by the sample web application displayed in the header section. Let's capture this in an Array list, as follows:
List<String> languages = new ArrayList<String>();
languages.add("English");
languages.add("German");
languages.add("French");
If we have to print the list members, we will use a for loop in the following...