Java 8 – How to Sort List by java.time.ZonedDateTime in 4 ways ?

In this article, we will discuss and learn how to sort List by java.time.ZonedDatetime in ascending as well as descending order in different ways

Sort List by java.time.ZonedDateTime in 4 ways:

  1. Using java.util.Comparator
  2. Using Lambda expression
  3. Using Method References
  4. Using Stream API

We have Product class with 4 member variables, its setters & getters, 4-arg parameterized constructor and overriding toString() method for pretty print. We will sort List of Products on the basis of java.time.ZonedDateTime in ascending and descending order in 4 different ways as mentioned above.

Product.java

package in.bench.resources.zoneddatetime.sorting;

import java.time.ZonedDateTime;

public class Product {

	// member variables
	private int prodId;
	private String prodName;
	private ZonedDateTime prodCreatedDate;
	private double prodRate;


	// getters and setters


	// 4-arg parameterized constructor


	// override toString() method
	@Override
	public String toString() {
		return "Product [prodId=" + prodId 
				+ ", prodRate=" + prodRate 
				+ ", prodName=" + prodName 
				+ ",\n\t\t prodCreatedDate=" + prodCreatedDate
				+ "]";
	}
}

1. Sort Product List by ZonedDateTime using java.util.Comparator

  • There is a list of Products and we will be sorting product list by java.time.ZonedDateTime in ascending and descending order using java.util.Comparator interface
  • For sorting,
    • We will create separate class implementing java.util.Comparator interface and overriding compare() method for ascending-order sorting
    • For descending-order sorting, we will reverse the Comparator using reversed() method
  • Finally, we will print product list to the console in ascending and descending order
  • Note: For Product created attribute, Date(day, month, year) and Time(hour, minute, second, nano) part/fields are same for all 5 products added to the list except ZoneId which is different for each products

ProductSortingComparator.java

package in.bench.resources.zoneddatetime.sorting;

import java.util.Comparator;

public class ProductSortingComparator implements Comparator<Product> {

	@Override
	public int compare(Product prod1, Product prod2) {
		return prod1.getProdCreatedDate().compareTo(prod2.getProdCreatedDate());
	}
}

ProductZonedDateTimeSortingUsingComparator.java

package in.bench.resources.zoneddatetime.sorting;

import java.text.ParseException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ProductZonedDateTimeSortingUsingComparator {

	public static void main(String[] args) throws ParseException {

		// 1. products
		Product product1 = new Product(1, "Cooker", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Africa/Nairobi")), 13750.0);
		Product product2 = new Product(2, "Sofa-Bed", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("America/New_York")), 11750.0);
		Product product3 = new Product(3, "Fridge", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Asia/Kolkata")), 12750.0);
		Product product4 = new Product(4, "Cupboard", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Australia/Sydney")), 11525.0);
		Product product5 = new Product(5, "Utensils", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Europe/Paris")), 17050.0);


		// 1.1 List of Products
		List<Product> products = new ArrayList<Product>();
		products.add(product1);
		products.add(product2);
		products.add(product3);
		products.add(product4);
		products.add(product5);


		// 1.2 print to console
		System.out.println("Before sorting :- \n");
		for(Product prod : products) {
			System.out.println(prod);
		}


		// 2. Ascending-order sorting
		Collections.sort(products, new ProductSortingComparator());


		// 2.1 print to console - ascending order
		System.out.println("\n\nAscending-order sorting on the basis of ZonedDateTime :- \n");
		for(Product prod : products) {
			System.out.println(prod);
		}


		// 3. Descending-order sorting
		Collections.sort(products, (new ProductSortingComparator()).reversed());


		// 3.1 print to console - descending order
		System.out.println("\n\nDescending-order sorting on the basis of ZonedDateTime :- \n");
		for(Product prod : products) {
			System.out.println(prod);
		}
	}
}

Output:

Before sorting :- 

Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]


Ascending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]


Descending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]

2. Sort Product List by ZonedDateTime using Lambda Expression

  • There is a list of Products and we will be sorting product list by java.time.ZonedDateTime in ascending and descending order using Lambda Expression
  • For sorting, we will write/code lambda expression to sort list of product on the basis of product created date which will return Comparator
    • For ascending-order sorting, we will pass actual list and Comparator to Collections.sort() method
    • For descending-order sorting, we will reverse the Comparator using reversed() method and pass actual list and reversed Comparator to Collections.sort() method
  • Finally, we will print product list to the console in ascending and descending order
  • Note: For Product created attribute, Date(day, month, year) and Time(hour, minute, second, nano) part/fields are same for all 5 products added to the list except ZoneId which is different for each products

ProductZonedDateTimeSortingUsingLambdaExpression.java

package in.bench.resources.zoneddatetime.sorting;

import java.text.ParseException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ProductZonedDateTimeSortingUsingLambdaExpression {

	public static void main(String[] args) throws ParseException {

		// 1. products
		Product product1 = new Product(1, "Cooker", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Africa/Nairobi")), 13750.0);
		Product product2 = new Product(2, "Sofa-Bed", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("America/New_York")), 11750.0);
		Product product3 = new Product(3, "Fridge", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Asia/Kolkata")), 12750.0);
		Product product4 = new Product(4, "Cupboard", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Australia/Sydney")), 11525.0);
		Product product5 = new Product(5, "Utensils", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Europe/Paris")), 17050.0);


		// 1.1 List
		List<Product> products = new ArrayList<Product>();
		products.add(product1);
		products.add(product2);
		products.add(product3);
		products.add(product4);
		products.add(product5);


		// 1.2 print to console
		System.out.println("Before sorting :- \n");
		products.forEach(prod -> System.out.println(prod));


		// 2. get Comparator using Lambda expression
		Comparator<Product> comparatorAsc = (prod1, prod2) -> prod1.getProdCreatedDate()
				.compareTo(prod2.getProdCreatedDate());


		// 2.1 pass above Comparator and sort in ascending order
		Collections.sort(products, comparatorAsc);


		// 2.2 print to console
		System.out.println("\n\nAscending-order sorting on the basis of ZonedDateTime :- \n");
		products.forEach(prod -> System.out.println(prod));


		// 3. get Comparator using Lambda expression
		Comparator<Product> comparatorDesc = (prod1, prod2) -> prod2.getProdCreatedDate()
				.compareTo(prod1.getProdCreatedDate());


		// 3.1 pass above Comparator and sort in descending order
		Collections.sort(products, comparatorDesc);


		// 3.2 print to console - descending order
		System.out.println("\n\nDescending-order sorting on the basis of ZonedDateTime :- \n");
		products.forEach(prod -> System.out.println(prod));
	}
}

Output:

Before sorting :- 

Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]


Ascending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]


Descending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]

3. Sort Product List by ZonedDateTime using Method References

  • There is a list of Products and we will be sorting product list by java.time.ZonedDateTime in ascending and descending order using Method References
  • For sorting, create a Comparator by passing Method References to Comparator.comparing() method
    • For ascending-order sorting, pass above created Comparator to List.sort() method as argument
    • For descending-order sorting, we will reverse the Comparator using reversed() method and pass reversed Comparator to List.sort() method as argument
  • Finally, we will print product list to the console in ascending and descending order
  • Note: For Product created attribute, Date(day, month, year) and Time(hour, minute, second, nano) part/fields are same for all 5 products added to the list except ZoneId which is different for each products

ProductZonedDateTimeSortingUsingMethodReferences.java

package in.bench.resources.zoneddatetime.sorting;

import java.text.ParseException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class ProductZonedDateTimeSortingUsingMethodReferences {

	public static void main(String[] args) throws ParseException {

		// 1. products
		Product product1 = new Product(1, "Cooker", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Africa/Nairobi")), 13750.0);
		Product product2 = new Product(2, "Sofa-Bed", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("America/New_York")), 11750.0);
		Product product3 = new Product(3, "Fridge", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Asia/Kolkata")), 12750.0);
		Product product4 = new Product(4, "Cupboard", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Australia/Sydney")), 11525.0);
		Product product5 = new Product(5, "Utensils", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Europe/Paris")), 17050.0);


		// 1.1 List
		List<Product> products = new ArrayList<Product>();
		products.add(product1);
		products.add(product2);
		products.add(product3);
		products.add(product4);
		products.add(product5);


		// 1.2 print to console
		System.out.println("Before sorting :- \n");
		products.forEach(System.out::println);


		// 2. ascending-order sorting using Method References
		products.sort(Comparator.comparing(Product::getProdCreatedDate));


		// 2.1 print to console
		System.out.println("\n\nAscending-order sorting on the basis of ZonedDateTime :- \n");
		products.forEach(System.out::println);


		// 3. descending-order sorting using Method References
		products.sort(Comparator.comparing(Product::getProdCreatedDate).reversed());


		// 3.1 print to console - descending order
		System.out.println("\n\nDescending-order sorting on the basis of ZonedDateTime :- \n");
		products.forEach(System.out::println);
	}
}

Output:

Before sorting :- 

Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]


Ascending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]


Descending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]

4. Sort Product List by ZonedDateTime using Stream API

  • There is a list of Products and we will be sorting product list by java.time.ZonedDateTime in ascending and descending order using Stream API
  • For sorting, create a Comparator by passing Method References to Comparator.comparing() method
  • Finally, we will print product list to the console in ascending and descending order
  • Note: For Product created attribute, Date(day, month, year) and Time(hour, minute, second, nano) part/fields are same for all 5 products added to the list except ZoneId which is different for each products

ProductZonedDateTimeSortingUsingStreamAPI.java

package in.bench.resources.zoneddatetime.sorting;

import java.text.ParseException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class ProductZonedDateTimeSortingUsingStreamAPI {

	public static void main(String[] args) throws ParseException {

		// 1. products
		Product product1 = new Product(1, "Cooker", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Africa/Nairobi")), 13750.0);
		Product product2 = new Product(2, "Sofa-Bed", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("America/New_York")), 11750.0);
		Product product3 = new Product(3, "Fridge", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Asia/Kolkata")), 12750.0);
		Product product4 = new Product(4, "Cupboard", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Australia/Sydney")), 11525.0);
		Product product5 = new Product(5, "Utensils", 
				ZonedDateTime.of(2022, 7, 24, 5, 29, 59, 999, ZoneId.of("Europe/Paris")), 17050.0);


		// 1.1 List
		List<Product> products = new ArrayList<Product>();
		products.add(product1);
		products.add(product2);
		products.add(product3);
		products.add(product4);
		products.add(product5);


		// 1.2 print to console
		System.out.println("Before sorting :- \n");
		products.stream().forEach(prod -> System.out.println(prod));


		// 2. ascending-order sorting
		List<Product> sortedProductListAsc = products
				.stream()
				.sorted(Comparator.comparing(Product::getProdCreatedDate))
				.collect(Collectors.toList());


		// 2.1 print to console
		System.out.println("\n\nAscending-order sorting on the basis of ZonedDateTime :- \n");
		sortedProductListAsc.stream().forEach(prod -> System.out.println(prod));


		// 3. descending-order sorting
		List<Product> sortedProductListDesc = products
				.stream()
				.sorted(Comparator.comparing(Product::getProdCreatedDate).reversed())
				.collect(Collectors.toList());


		// 3.1 print to console - descending order
		System.out.println("\n\nDescending-order sorting on the basis of ZonedDateTime :- \n");
		sortedProductListDesc.stream().forEach(prod -> System.out.println(prod));
	}
}

Output:

Before sorting :- 

Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]


Ascending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]


Descending-order sorting on the basis of ZonedDateTime :- 

Product [prodId=2, prodRate=11750.0, prodName=Sofa-Bed,
		 prodCreatedDate=2022-07-24T05:29:59.000000999-04:00[America/New_York]]
Product [prodId=5, prodRate=17050.0, prodName=Utensils,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+02:00[Europe/Paris]]
Product [prodId=1, prodRate=13750.0, prodName=Cooker,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+03:00[Africa/Nairobi]]
Product [prodId=3, prodRate=12750.0, prodName=Fridge,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+05:30[Asia/Kolkata]]
Product [prodId=4, prodRate=11525.0, prodName=Cupboard,
		 prodCreatedDate=2022-07-24T05:29:59.000000999+10:00[Australia/Sydney]]

Related Articles:

References:

Happy Coding !!
Happy Learning !!

Java 8 – How to Sort List by java.time.OffsetDateTime in 4 ways ?
Java 8 - OffsetTime with method details and examples