How to sort strings alphabetically in Java?

To sort strings alphabetically in Java, use either Collections.sort or Arrays.sort.

Sort a list of strings

java.util.List<String> list = new java.util.ArrayList<>();
list.add("Zack");
list.add("Susie");
list.add("Anna");

java.util.Collections.sort(list);

// [Anna, Susie, Zack]
System.out.println(list);

Sort an array of strings

String[] array = new String[] { "Zack", "Susie", "Anna" };

java.util.Arrays.sort(array);

// [Anna, Susie, Zack]
System.out.println(java.util.Arrays.toString(array));