Consider TreeSet.
import java.util.*;
class TestCollection11{
public static void main(String args[]) {
//Creating and adding elements
TreeSet<String> al=newal = new TreeSet<String>();
al.add("Ravi");
al.add("Vijay");
al.add("Ravi");
al.add("Ajay");
//Traversing elements
Iterator<String> itr=alitr = al.iterator();
while( itr.hasNext() ) {
System.out.println(itr.next());
}
}
}
outputs
Ajay
Ravi
Vijay
Indeed, choosing the best data structure makes life easier.