Challenge 3: Sorting Strings by Length with Comparator.comparing() — Possible Solution ==================================================================== LengthSortDemo.java: import java.util.ArrayList; import java.util.Comparator; import java.util.List; public class LengthSortDemo { public static void main(String[] args) { List names = new ArrayList<>(List.of("Alexandra", "Bo", "Charlotte", "Sam")); names.sort(Comparator.comparing(String::length)); System.out.println(names); } } Output: [Bo, Sam, Alexandra, Charlotte] Explanation: String::length is a method reference supplying the sort key -- Comparator.comparing() builds a Comparator that orders elements by comparing the RESULT of calling length() on each one, rather than comparing the strings themselves alphabetically. This is exactly the "external ordering logic" the chapter describes: String's own natural ordering (alphabetical, via Comparable) is never touched here at all. WHY THIS WORKS AS AN ANSWER ------------------------------ This uses Comparator.comparing() to sort by a property (length) other than the type's natural ordering, matching the chapter's own stated use case for Comparator over Comparable -- when the natural ordering isn't the one actually needed.