Sort Vector in descending order using comparator - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Sort Vector in descending order using comparator

Demo Code

 
import java.util.Vector;
import java.util.Collections;
import java.util.Comparator;
 
public class Main {
 
  public static void main(String[] args) {
    Vector v = new Vector();
   //w w  w. j a  va2 s  . c om
    v.add("1");
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");
   
    Comparator comparator = Collections.reverseOrder();
   
    System.out.println("Before sorting Vector in descending order : " + v);
   
    Collections.sort(v,comparator);
    System.out.println("After sorting Vector in descending order : " + v);
  }
}

Result


Related Tutorials