0
How to sort string array?
A-Z for example input: dog bat cat Output: bat cat dog
3 Antworten
+ 4
Jason Cuerbo ,
Hello 👋.
You didn't tell how input will be given. (as space seperated values in single string? or in an array ?)
If it's array you can use Arrays.sort() method to sort in-place.
Arrays class is defined in java.util package so import it before use or use fully qualified class name.
String [] names = {"cat","bat","dog","crow"};
java.util.Arrays.sort(names);
for(var name : names)
System.out.println(name + " ")
I hope this helps. Try this in playground or wherever you'd like to. First try it yourself. Let me know if you feel any difficulty 👍
0
Thank you 😊
0
How about words? Like dog bat cat and then the output is bat cat dog