How do I sort array values in case insensitive order?

Bookmark this example!  
Category: java.util, viewed: 1208 time(s).

By default the when sorting an arrays the value will be ordered in case-sensitive order. This example show you how to order it in case-insensitive order.

 
package org.kodejava.example.util;
 
import java.util.Arrays;
import java.util.Collections;
 
public class SortArrayCaseSensitivity {
public static void main(String[] args) {
        String[] teams = new String[5];
        teams[0] = "Manchester United";
        teams[1] = "chelsea";
        teams[2] = "Arsenal";
        teams[3] = "liverpool";
        teams[4] = "EVERTON";
 
        //
        // Sort array, by default it will be sort in case sensitive order.
        // [Arsenal, EVERTON, Manchester United, chelsea, liverpool]
        //
        Arrays.sort(teams);
        System.out.println(Arrays.toString(teams));
 
        //
        // Sort array in case insensitive order
        // [Arsenal, chelsea, EVERTON, liverpool, Manchester United]
        //
        Arrays.sort(teams, String.CASE_INSENSITIVE_ORDER);
        System.out.println(Arrays.toString(teams));
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!
Firefox 2
Google

100 Top & Latest

GetJava Download Button

Locations of visitors to this page
eXTReMe Tracker
visitor stats