Listnames = new ArrayList<>(); names.add("Alice"); names.add("Bob"); names.add("Charlie"); names.sort(Comparator.naturalOrder()); // Output: Alice, Bob, Charlie
Listnumbers = Arrays.asList(5, 2, 8, 1, 6); numbers.sort(Comparator.reverseOrder()); // Output: 8, 6, 5, 2, 1
public class Person { private String name; private int age; // constructor and getters/setters omitted for brevity } ListPackage library: `java.util`people = new ArrayList<>(); people.add(new Person("Alice", 25)); people.add(new Person("Bob", 30)); people.add(new Person("Charlie", 20)); people.sort(Comparator.comparing(Person::getAge)); // Output: Charlie, Alice, Bob