Home java How to sort strings alphabetically in java?

How to sort strings alphabetically in java?




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);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions