Consider [TreeSet](https://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.html). > From [javatpoint.com : treeset](https://www.javatpoint.com/java-treeset) import java.util.*; class TestCollection11{ public static void main(String args[]) { //Creating and adding elements TreeSet<String> al = new TreeSet<String>(); al.add("Ravi"); al.add("Vijay"); al.add("Ravi"); al.add("Ajay"); //Traversing elements Iterator<String> itr = al.iterator(); while( itr.hasNext() ) { System.out.println(itr.next()); } } } outputs Ajay Ravi Vijay Indeed, choosing the best data structure makes life easier.