Hi,
See the code sample below

Java Code:
import java.util.*;
public class Test {
    
    public static void main(String[] args) {
    	
    	Scanner scanner = new Scanner(System.in);
    	int counter, index;
    	
    	Vector<String> string = new Vector<String>();
    	System.out.println("Please enter five names");
    	System.out.print("First name: ");
    	String name1 = scanner.next();
    	System.out.print("Second name: ");
    	String name2 = scanner.next();
    	System.out.print("Third name: ");
    	String name3 = scanner.next();
    	System.out.print("Fourth name: ");
    	String name4 = scanner.next();
    	System.out.print("Fifth name: ");
    	String name5 = scanner.next();
    	
    	string.addElement(name1);
    	string.addElement(name2);
    	string.addElement(name3);
    	string.addElement(name4);
    	string.addElement(name5);

    	Object vectorArray[] = string.toArray();

		//using compareTo method sorting is happening
		for(int i=0;i<(vectorArray.length-1);i++)
		{
			for (int j=i+1;j<vectorArray.length;j++)
			{
				if(vectorArray[i].toString().compareTo(vectorArray[j].toString()) > 0 )
				{
					Object x,y,temp;
					temp=vectorArray[i];
					vectorArray[i]=vectorArray[j];
					vectorArray[j] = temp;

				} 

			System.out.println(vectorArray.length);
    		
		}//for
	}//for

     //After sorting again converted back to Vector
     Vector v = new Vector(Arrays.asList(vectorArray));
	 System.out.println(v);
 }//main
}//class