Java ArrayList Sort: Ascending and Descending Order
Learn to sort Java ArrayList in ascending and descending order using ArrayList.sort(), Collections.sort(), Comparator interface and Java 8 Streams.
Learn to sort Java ArrayList in ascending and descending order using ArrayList.sort(), Collections.sort(), Comparator interface and Java 8 Streams.
Learn to sort a Java Set, List and Map of primitive types and custom objects using Comparator, Comparable and new lambda expressions. We will learn to sort in ascending and descending order as well. 1. Sorting a List of Objects To sort a list of objects, we have two popular …
Learn to sort a Java List or Stream with Comparator‘s nullsFirst() and nullsLast() methods. The Stream may contain null values, or the custom objects may have null field values. Failing to handle the null values during comparison will cause NullPointerException in runtime. 1. Introduction In this tutorial, we will learn …
Learn to sort an array of strings alphabetically. In given java program, strings are given as input from console and after sorting – printed in the console.
Learn to request partial data from the database using pagination and sorting inputs using the query parameters in spring boot and data apps.
Java 8 example to sort stream of objects by multiple fields using comparators and Comparator.thenComparing() method. This method returns a lexicographic-order comparator with another comparator. It gives the same effect as SQL group by clause.
Learn to sort stream of numbers and strings in ascending (natural order) and descending orders (reverse order) using Stream.sorted() method.
Learn to use Stream sorted() method to sort a stream of elements in their natural order and also according to the provided Comparator.
Java examples to do SQL-style group by sort on list of objects. It involves using multiple comparators, each of which is capable of sorting on different field in model object. Table of Contents 1. Model class and multiple comparators 2. Comparator.thenComparing() 3. CompareToBuilder 4. ComparisonChain 5. Chained comparators 1. Model …
Learn to sort a string alphabetically using Stream.sort(), Arrays.sort() and custom sort() method using simple arrays and swapping example.
Java 8 example of sorting a collection of objects on multiple fields (ORDER BY sort) using Comparator thenComparing() method.
Learn to use Collections.sort() method to sort a list of objects using some examples. By default, the sort() method sorts a given list into ascending order (or natural order). We can use Collections.reverseOrder() method, which returns a Comparator, for reverse sorting. 1. Sorting in Natural Order and Reverse Order 1.1. …
Learn to sort a Java array of primitives, strings and custom objects in multiple ways with the help of Comparable and Comparator interfaces, Arrays.sort() and Stream.sorted() APIs. We will learn to sort arrays in natural ordering, reverse ordering and any other custom ordering as well. 1. Basics of Array Sorting …
Simple and easy-to-understand examples of sorting a HashMap by values, using Java 8 Stream, in ascending and descending (reverse) orders.
Simple and easy-to-understand examples to sort a Map by key, using TreeMap and Java 8 Stream, in ascending and descending (reverse) orders.
Quicksort follows the divide-and-conquer approach and works by dividing the input array into two sub-arrays, then recursively sorting each sub-array before merging.
Bubble Sort is a simple and slow sorting algorithm that repeatedly steps through the collection, compares each pair of adjacent elements and swaps them if they are in the wrong order.
Selection Sort is a simple and slow sorting algorithm that repeatedly selects the lowest or highest element from the unsorted array and moves it to the end of the sorted array.
Learn insertion sort with in-depth exploration of the algorithm, complexity, implementation in Java, and key advantages and disadvantages.
Merge sort functions by partitioning the input into smaller sub-arrays, sorting each sub-array recursively, and subsequently merging the sorted sub-arrays.
Easy to follow examples of sorting a collection of objects in any order using Comparable or Comparator Interfaces.
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.