Sort elemnts in an ArrayList using Comparator.
public static void sortAnyList(){ ArrayList aList = new ArrayList(); aList.add("Danny"); aList.add("Maddy"); aList.add("Rahul"); aList.add("Nilesh"); aList.add("Pranjna"); aList.add("Rohit"); Collections.sort(aList, new Comparator() { public int compare(Object o1, Object o2) { String s1 = (String)o1; String s2 = (String)o2; return s1.compareTo(s2); } }); }