---------------------------------------------------------------------SortableVector.java:---------------------------------------------------------------------import java.util.*;/*** A simple extension to the java.util.Vector class which provides* a method to sort the elements.*/public class SortableVectorextends Vector{ /** * Sorts the elements of the vector using a simple O(n^2) selection * sort. The comp argument must be an object which implements the * ElementComparator interface. */ public void sort(ElementComparator comp) { int smallest; for (int i = 0; i < elementCount - 1; ++i) { //find smallest remaining element smallest = i; for (int j = i + 1; j < elementCount; ++j) { if (comp.preceeds(elementData[j], elementData[smallest])) { smallest = j; } } //exchange smallest and i if (smallest != i) { Object tmp = elementData[i]; elementData[i] = elementData[smallest]; elementData[smallest]= tmp; } } } /** * Testing purposes only. */ public static void main(String args[]) { //Create new vector SortableVector v = new SortableVector(); System.out.println("Creating vector..."); v.addElement("completely unsorted: 3"); v.addElement("completely unsorted: 5"); v.addElement("completely unsorted: 2"); v.addElement("completely unsorted: 1"); v.addElement("completely unsorted: 4"); v.addElement("already sorted: 1"); v.addElement("already sorted: 2"); v.addElement("already sorted: 3"); v.addElement("already sorted: 4"); v.addElement("already sorted: 5"); v.addElement("descending: 5"); v.addElement("descending: 4"); v.addElement("descending: 3"); v.addElement("descending: 2"); v.addElement("descending: 1"); //Sort data System.out.println("sorting..."); v.sort(new ElementComparator() { public boolean preceeds(Object element1, Object element2) { return ((String)element1).compareTo((String)element2) < 0; } }); //Output sorted data Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(" " + (String)e.nextElement()); } }}---------------------------------------------------------------------ElementComparator.java:---------------------------------------------------------------------/*** This interface implements a single method preceeds which returns* true if both arguments are in ascending order (i.e. if element1* preceeds element2). Otherwise it returns false. It is used as an* argument to the the sort method of the SortableVector class.*/public interface ElementComparator{ public boolean preceeds(Object element1, Object element2);}