How to sort string array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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