This will solve your problem...
ArrayList arrayList = new ArrayList();
//Add elements to Arraylist
arrayList.add("1");
arrayList.add("3");
arrayList.add("5");
arrayList.add("2");
arrayList.add("4");
Collections.sort(arrayList);
//display elements of ArrayList
System.out.println("ArrayList elements after sorting in ascending order : ");
for(int i=0; i<arrayList.size(); i++)
System.out.println(arrayList.get(i));
To sort an ArrayList object, use Collection.sort
method. This is a
static method. It sorts an ArrayList object's elements into ascending order.
Just in case if the below code in comment doesnt work means...
Try this code..
Create a custom comparator class:
import java.util.Comparator;
class IgnoreCaseComparator implements Comparator<String> {
public int compare(String strA, String strB) {
return strA.compareToIgnoreCase(strB);
}
}
Then on your sort:
IgnoreCaseComparator icc = new IgnoreCaseComparator();
java.util.Collections.sort(arrayList,icc);