sort string list alphabetically java code example
Example 1: java sort string characters alphabetically
import java.util.Arrays;
public class CharactersAlphabetically
{
public static void main(String[] args)
{
String strInput = "flowerbrackets";
char[] ch = strInput.toCharArray();
Arrays.sort(ch);
String strSorted = String.valueOf(ch);
System.out.println("sort string characters alphabetically: " + strSorted);
}
}
Example 2: java sort list alphabetically
Assuming that those are Strings, use the convenient static method sort…
java.util.Collections.sort(listOfCountryNames)