Sort a Vector with Collections.sort() in Java

Vector follows the insertion order, which means that the elements are displayed in the order in which they were inserted in Vector. This example shows how to sort Vector elements in ascending order using the Collections.sort(). The steps to follow are as follows:
  1. Create Vector object
  2. Add elements to Vector with the add(Object o)
  3. Order Vector with Collection.sort(Vector v)
  4. Show sorted Vector
import java.util.Collections; 
import java.util.Vector;
public class VectorSort {
public static void main(String[] args) {

//create vector
Vector vector = new Vector();

//add elements to vector
vector.add("d");
vector.add("e");
vector.add("a");
vector.add("c");
vector.add("f");
vector.add("b");

// default Vector maintains the insertion order
System.out.println("Vector before sorting:");
System.out.println(vector);

// Collections.sort() sorts items in ascending order
Collections.sort(vector);

//Show elements after sorting
System.out.println("Vector after sorting :");
System.out.println(vector);
}
}
Output:

Vector before sorting: 
[d, e, a, c, f, b]
Vector after sorting:
[a, b, c, d, e, f]