Sort string array in java – case sensitive and case insensitive

Here’s the java program on sort string array in java – case sensitive and case insensitive,

Also read – sort string array in java

import java.util.Arrays;
public class SortStringCaseInsensitive 
{
public static void main(String[] args)
{
String strPlaces[] = new String[]{"Great Barrier Reef", "denmark", "bora bora",
"Florence","Tokyo", "cusco"};
Arrays.sort(strPlaces);
System.out.println("CASE SENSITIVE ORDER : ");
System.out.println(Arrays.toString(strPlaces));
      Arrays.sort(strPlaces, String.CASE_INSENSITIVE_ORDER);
System.out.println("CASE INSENSITIVE ORDER : ");
System.out.println(Arrays.toString(strPlaces));
}
}

Output:

CASE SENSITIVE ORDER : [Florence, Great Barrier Reef, Tokyo, bora bora, cusco, denmark]
CASE INSENSITIVE ORDER : [bora bora, cusco, denmark, Florence, Great Barrier Reef, Tokyo]

Related Posts