Submitted by: Octavia Anghel(octaviaanghel@gmail.com)

Thursday Apr 23rd 2020 by Octavia Anghel
Article Image

Language: Java, Expertise: Intermediate: Learn how to sort an array by chaining ordering with Guava.

Guava allows us to sort an array by chaining ordering, as shown in the example below:

List cars = Arrays.asList(
  new Car("Dacia", 21000),
  new Car("Audi", 30000), 
  new Car("Fiat", null));
Ordering ordering = Ordering
  .onResultOf(new Function() {
      public Comparable apply(Car car) {
          return car.price;
Mobile Site | Full Site