I assume the array contains String objects. You can wrap each String object in another object that implements the Comparable interface, so you can ignore case:
Code:
class MyString implements Comparable
{
public String s = null;
public int compareTo( Object o )
{
return s.compareToIgnoreCase( ((MyString)o).s)
}
}
When you sort the array of MyString objects, they will sort case-insensitive.
Most sort algoritums can take an optional comparator which is a class that has just the compareTo method (with 2 parameters). Which means that you don't need to wrap the strings to do the above -- cutting down on code. I'm not sure about the sort that takes an array, but most first class ordered containers will handle a comparator.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.