Java 17 sort (Comparable) with lambda and Record

In this example we can see record Person and we use stream’s sorted(Comparator<? super T> comparator) method to sort the List of people by their age. So sorted(Comparator<? super T> comparator) accept as parameter Comparator. For this reason we have to create Comparator and we sort inside by age. The documentation for sorted(Comparator<? super T> comparator) state: Returns … Read more