Java Collection How to - Sort array in alphabetical order








Question

We would like to know how to sort array in alphabetical order.

Answer

import java.util.Arrays;
//from   w ww  .j  a v  a2  s. com
public class Main {
  public static void main(String[] args) {

    String[] myStrArray = new String[] { "c", "a", "b" };

    Arrays.sort(myStrArray, String.CASE_INSENSITIVE_ORDER);

    for (int a = 0; a < myStrArray.length; a++) {
      System.out.println(myStrArray[a]);
    }
  }

}

The code above generates the following result.