List Interface sort() method in Java 8

We also have a new sort() method on List Interface. It sorts content of the list by providing a Comparator. Here we can write a Comparator in very new way in JDK8, which we will see in our example code below.

Let see an example of List Interface sort() method.

tenisTournamnetList is list of String and String of characters in java already comparable. So I can use Comparator naturalOrder() method to compare them. So this call will sort the content of tenisTournamnetList in alphabetical order and output of the code will be:


Leave a Reply