0

How to sort string array?

A-Z for example input: dog bat cat Output: bat cat dog

19th Feb 2020, 4:23 PM
Jason Cuerbo
Jason Cuerbo - avatar
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 👍
19th Feb 2020, 5:45 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
0
Thank you 😊
19th Feb 2020, 4:24 PM
Jason Cuerbo
Jason Cuerbo - avatar
0
How about words? Like dog bat cat and then the output is bat cat dog
19th Feb 2020, 4:27 PM
Jason Cuerbo
Jason Cuerbo - avatar