Loading lesson…
Level 1 · Apprentice0 XP
Passing behaviour as a value, the idea behind streams and most modern APIs.
Step 1 / 5
ProblemTo sort by name you once wrote an anonymous class: new Comparator<User>() with an overridden method, braces and a return. The one idea, 'compare by name', is hidden in ceremony.
← → step
Before this: Exceptions
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a method List<T> keep(List<T> items, Predicate<T> test) and use it three ways: with a lambda, with a method reference, and with two predicates combined by and(). Then sort a list of people by age, then by name, using Comparator.comparing.