-4

was wondering if someone could write an example code for elements of array being displayed in alphabetical order. The elements have come from the users input and have been stored in the array. Thanks.

A97
  • 23
  • 4

1 Answers1

2

A simple example

String[] strArray = {"Carol", "bob", "Alice"};
Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
System.out.println(Arrays.toString(strArray));
Jun Huh
  • 242
  • 1
  • 8
  • Note that this Comparator `String.CASE_INSENSITIVE_ORDER` does not take locale into account, and will result in an unsatisfactory ordering for certain locales. – Patrick Parker Mar 02 '18 at 18:16