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.
Asked
Active
Viewed 101 times
-4
-
To clarify, is it a `String[]`? – Mureinik Mar 02 '18 at 18:04
-
2StackOverflow is not a code writing service. Please put in a modicum of effort first. For example, search for "Java sort array". – Patrick Parker Mar 02 '18 at 18:05
-
Call some sort function, there are plenty build in. – Zabuzard Mar 02 '18 at 18:05
-
1Questions 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], [ask]). – Zabuzard Mar 02 '18 at 18:05
-
@Mureinik yes it is a string – A97 Mar 02 '18 at 19:18
-
@PatrickParker just need an example – A97 Mar 02 '18 at 19:21
1 Answers
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