The static utility method accepts a list and a comparator in order to sort the elements of the given list. You often find yourself creating anonymous comparators and pass them to the sort method.

As you can see the code is much shorter and easier to read. But it gets even shorter:

List now has a method. Also the java compiler is aware of the parameter types so you can skip them as well. Let’s dive deeper into how lambda expressions can be used in the wild.