Java Collections sort with reversed order

Description

Java Collections sort with reversed order



import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Main {
  public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("HTML");
    arrayList.add("CSS");
    arrayList.add("C");
    arrayList.add("C++");
    arrayList.add("demo.com");
    /*from   w  w w  .  j  ava  2  s. c om*/
    Comparator<String> comparator = Collections.reverseOrder();
    System.out.println(arrayList);

    Collections.sort(arrayList, comparator);
    System.out.println(arrayList);
  }
}



PreviousNext

Related