-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.

6
  • To clarify, is it a String[]? Commented Mar 2, 2018 at 18:04
  • 2
    StackOverflow is not a code writing service. Please put in a modicum of effort first. For example, search for "Java sort array". Commented Mar 2, 2018 at 18:05
  • Call some sort function, there are plenty build in. Commented Mar 2, 2018 at 18:05
  • 1
    Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it (help center, How to Ask). Commented Mar 2, 2018 at 18:05
  • @Mureinik yes it is a string Commented Mar 2, 2018 at 19:18

1 Answer 1

2

A simple example

String[] strArray = {"Carol", "bob", "Alice"};
Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
System.out.println(Arrays.toString(strArray));
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this Comparator String.CASE_INSENSITIVE_ORDER does not take locale into account, and will result in an unsatisfactory ordering for certain locales.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.