February 2014
Beginner
1248 pages
62h 25m
English
Figure 17.11 demonstrates filtering Employees with an object that implements the functional interface Predicate<Employee>, which is defined with a lambda in lines 34–35. Defining lambdas in this manner enables you to reuse them multiple times, as we do in lines 42 and 49. Lines 41–44 output the Employees with salaries in the range 4000–6000 sorted by salary as follows:
• Line 41 creates a Stream<Employee> from the List<Employee>.
• Line 42 filters the stream using the Predicate named fourToSixThousand.
• Line 43 sorts by salary the Employees that remain in the stream. To specify a Comparator for salaries, we use the Comparator interface’s static method comparing. The method reference ...
Read now
Unlock full access