Sorting Java String Array ignoring the case

Hello,
I know the Ararys class give a series of sorting method in java. But I want to sort an array of strings ignoring the case. Do we have a quick way of doing in java within re-inventing the wheel?.

Eg. Given
String names[] = { "Joe", "Arnold", "Pearl", "andy", "jill", peter"};

Result
String names = {"andy", "Arnold", "jill", "Joe", "Pearl", "peter"}

Any ideas.
{Note : I am trying to avoid lengthy ways of doing this. I will evaluate the shortest way of doing this and award the points to that person}.
prainAsked:
Who is Participating?
 
Bart CremersJava ArchitectCommented:
       String[] names = { "Joe", "Arnold", "Pearl", "andy", "jill", "peter"};
        Arrays.sort(names, String.CASE_INSENSITIVE_ORDER);
        System.out.println("Arrays.toString(names) = " + Arrays.toString(names));
0
 
CEHJCommented:
           List lnames = new ArrayList(Arrays.asList(names));
            Collections.sort(lnames, String.CASE_INSENSITIVE_ORDER);
            System.out.println(lnames);
0
 
elfe69Commented:
You can use Arrays.sort():

Arrays.sort(names,String.CASE_INSENSITIVE_ORDER);


Or you can use a comparator, look at the sort() method in the Collection class and the Comparator class for that.
0
 
prainAuthor Commented:
I like Bart_Cr's method.
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.