June 2018
Beginner
722 pages
18h 47m
English
As we have mentioned already, a collection of type List preserves an order of the elements, so, naturally, it has also an ability to sort the elements, and the sort(Comparator<E>) method serves this purpose. This method became possible after functional programming was introduced with Java 8. We will talk about it in Chapter 17, Lambda Expressions and Functional Programming.
Now, we will just show you a few examples and point where to look for the standard comparators. We start with the following list:
List<String> list = new ArrayList<>();list.add("s3");list.add("s2");list.add("ab");//list.add(null); //throws NullPointerException for sorting // String.CASE_INSENSITIVE_ORDER // Comparator.naturalOrder() // ...
Read now
Unlock full access