Actually it is not clear how to sort strings alphabetically
Answer 1, authority 100%
If you have a wordsList
with String
objects:
Collections.sort (wordsList);
If you have wordsArray
with String
objects:
Arrays.sort (wordsArray);
If you have a string with words, and you want to sort the words in the string in alphabetical order, then you can use the method with an array on top, having previously created an array from the string: String [] wordsArray = "The string with words is located here ".split (" ");
Answer 2, authority 50%
import java.util. *;
ArrayList & lt; String & gt; abc = new ArrayList & lt; String & gt; ();
abc.add ("C");
abc.add ("A");
abc.add ("B");
Collections.sort (abc);