17.4.4 Filtering and Sorting a Stream and Collecting the Results

Lines 31–35 display the values greater than 4 in sorted order. First, line 32 creates a Stream<Integer>. Then line 33 filters the elements to locate all the values greater than 4. Next, line 34 indicates that we’d like the results sorted. Finally, line 35 collects the results into a List<Integer>, which is then displayed as a String.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.