In your comparator factory class, do something like this:
private static final Comparator<String> MYSTRING_COMPARATOR = new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
};
public static Comparator<String> getMyStringComparator() {
return MYSTRING_COMPARATOR;
This uses the compare to method which is case insensitive (why write your own). This way you can use Collections sort like this:
List<String> myArray = new ArrayList<String>();
//fill your array here
Collections.sort(MyArray, MyComparators. getMyStringComparator());