Collections

How to sort arraylist in descending order in java

package com.candidjava;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class ArrayListDescending {
  public static void main(String[] args) {
    ArrayList al = new ArrayList();
    al.add("reena");
    al.add("teena");
    al.add("anu");
    al.add("zahir");
    al.add("sonu");
    System.out.println("Unsorted Arraylist:");
    System.out.println(al);
    // Sorting in descending order
    System.out.println("Arraylist in descending order:");
    Collections.sort(al, Collections.reverseOrder());
    System.out.println(al);
    Iterator itr = al.iterator();
    while (itr.hasNext()) {
      String name = (String) itr.next();
      System.out.println(name);
    }
  }

}

OUTPUT

Unsorted Arraylist:
[reena, teena, anu, zahir, sonu]
Arraylist in descending order:
[zahir, teena, sonu, reena, anu]
zahir
teena
sonu
reena
anu