| Learn | Java - Lists - Sorting a generic list |
|---|
| Sorting a generic list The
Applying the former requires amending the class of list elements being sorted, which is not always possible. It might also be undesirable as although it provides the default sorting, other sorting orders may be required in different circumstances, or sorting is just a one off task. Consider we have a task of sorting objects that are instances of the following class: In order to use (Aside: many standard Java classes such as With the modification above, the we can easily sort a list of However, suppose that we wanted to sort This is where the In Java 8 you can use a lambda instead of an anonymous class. The latter reduces to a one-liner: Further, there Java 8 adds a default |
Read Article
https://develop.horje.com/learn/1434/reference