February 2014
Beginner
1248 pages
62h 25m
English
In Section 7.15, you learned how to sort arrays with the sort and parallelSort static methods of class Arrays. You’ll often sort the results of stream operations, so in lines 18–21 we’ll sort the values array using stream techniques and display the sorted values. First, line 19 creates a Stream<Integer> from values. Next, line 20 calls Stream method sorted which sort the elements—this results in an intermediate Stream<Integers> with the values in ascending order.
To display the sorted results, we could output each value using Stream terminal operation forEach (as in line 15 of Fig. 17.5). However, when processing streams, you often create new collections containing the results so that you can ...
Read now
Unlock full access