Java Core & Fundamentals Tutorial
Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.
In Java, we can sort collections of data using various sorting algorithms and Java’s built-in sorting capabilities provided by the java.util.Collections class or the Arrays class.
Learn by examples.
Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.
Sorting in Java for arrays, lists, maps, sets and streams with Comparable, Comparator chains, null handling, Collator and the common sorting mistakes.
Learn Java stream sort with null values using Comparator.nullsFirst() and nullsLast(), for null elements and null fields, and avoid the reversed() trap.
Sort a String alphabetically in Java with toCharArray() and Arrays.sort(), streams, case-insensitive order, emoji-safe codePoints() and a Collator.
Sort by multiple fields in Java with Comparator thenComparing(). Covers all six overloads, Collator names, map entries, 2D arrays and stable sorts.
Java Collections.sort() sorts a List in place. Learn natural order, Comparator and reverseOrder(), stability, List.sort() and the exceptions it throws.
Sort array in Java with Arrays.sort() and parallelSort(), including ranges, comparators, primitive arrays in descending order and 2D arrays by column.
Sort a Map by values in Java with Map.Entry.comparingByValue() and a LinkedHashMap, in ascending and descending order, with ties, top N and null values.
Sort a Map by keys in Java with a TreeMap or a stream and a LinkedHashMap, in both orders, with case-insensitive, numeric and null keys.
Sort a List in Java by natural order with Comparable or by any field with a Comparator. Compare List.sort, Collections.sort and Stream.sorted in code.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.