Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Apr 23, 2020

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Chaining Ordering in 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
  .natural()
  .nullsFirst()
  .onResultOf(new Function() {
      @Override
      public Comparable apply(Car car) {
          return car.price;
      }
});
Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
w3schools.com
html.net