Sort string array in java – case sensitive order and case insensitive order

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

Also read – sort string array in java

Sort string array in java – case sensitive order and case insensitive order

import java.util.Arrays;
public class SortStringArrayDemo 
{
   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