Sort ArrayList in Java: Ascending and Descending Order
Learn to sort ArrayList in Java in ascending and descending order with List.sort(), Comparator.reverseOrder(), Collections.sort() and streams.
Learn to sort ArrayList in Java in ascending and descending order with List.sort(), Comparator.reverseOrder(), Collections.sort() and streams.
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 array alphabetically in Java with Arrays.sort, ignore case, reverse it, use Collator for accents, and handle null elements.
Learn to request partial data from the database using pagination and sorting inputs using the query parameters in spring boot and data apps.
Sort by multiple fields in a Java stream with comparing() and thenComparing(), mix ascending and descending order, handle nulls and pick keys at runtime.
Learn how to sort a stream in Java by numbers, strings, object fields, descending order and null values, plus sorting map entries and collecting results.
Java Stream sorted() examples that sort in natural, reverse and custom order with Comparator, records and nulls, plus how it compares with List.sort().
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.
Learn quicksort in Java with a partition diagram, Lomuto and Hoare code, pivot choice, worst-case fixes and a comparison with Arrays.sort() on Java 25.
Learn bubble sort in Java with a pass-by-pass diagram, the basic and optimized code, sorting objects, and timings against selection and insertion sort.
Learn selection sort in Java with a step diagram, code for arrays and objects, why it is not stable, and how it compares with other simple sorts.
Learn insertion sort in Java with a step diagram, shifting and binary insertion code, and why it beats Arrays.sort() on small or nearly sorted arrays.
Learn merge sort in Java with a split and merge diagram, top-down and bottom-up code, stability, memory use and a comparison with TimSort on Java 25.
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.