The Stream class was introduced in Java and supports a variety of methods to process a stream. The methods can be chained together, reducing the number of source statements and the need for intermediate variables. In addition, many types of process flow can be implemented. To learn how to chain stream operations together, follow these four steps.
streammethod returns a stream. The stream is then passed to the
filtermethod. This method returns a stream whose elements satisfy the search criteria, i.e., musical instruments whose names begin with "T". The stream that is output from the filter operation is passed to the
forEach. This method iterates through each element and applies the operation specified, which in this case is
System.out.println. Therefore, each element will be displayed on the console.