Sort the Array of String Lexicographically [Duplicate]
I Have an Array of String in Java. How Do I Sort It Lexicographically? Is There Any Built-in Function in Collection. Sort or Arrays. Sort? for Example: 0)...
I have an array of string in Java. How do I sort it lexicographically? Is there any built-in function in Collection.sort or Arrays.sort?
For example:
0) BANANA
1) ANANA
2) NANA
3) ANA
4) NA
5) A
after sorting:
5) A
3) ANA
1) ANANA
0) BANANA
4) NA
2) NANA
String[] strings = { " Hello ", " This ", "is ", "Sorting ", "Example" };
Arrays.sort(strings);
reverse:
String[] strings = { " Hello ", " This ", "is ", "Sorting ", "Example" };
Arrays.sort(strings, Collections.reverseOrder());
String[] a = { "BANANA", "ANANA", "NANA", "ANA", "NA", "A" };
Arrays.sort(a);
You have just to look at the javaDocs API references for how to sort arrays.