Weird, your code seems to work for me:

import java.util.Arrays;

public class Test
{
    public static void main(String[] args)
    {
        // args is the list of guests
        Arrays.sort(args);
        for(int i = 0; i < args.length; i++)
            System.out.println(args[i]);
    }
}

I ran that code using "java Test Bobby Joe Angel" and here is the output:

$ java Test Bobby Joe Angel
Angel
Bobby
Joe
Answer from Vineet Kosaraju on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ sorting a string alphabetically in java
Sorting a String Alphabetically in Java | Baeldung
March 17, 2024 - @Test void givenString_whenSort_thenSorted() { String abcd = "bdca"; char[] chars = abcd.toCharArray(); Arrays.sort(chars); String sorted = new String(chars); assertThat(sorted).isEqualTo("abcd"); } In Java 8, we can leverage the Stream API to sort the String for us:
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ java examples โ€บ java โ€“ sorting a string array in alphabetical order
Java - Sorting a String Array in Alphabetical Order
September 16, 2022 - Learn to arrange an array of strings alphabetically using Stream.sorted() and Arrays.sort() methods. Also, learn to reverse sort using Comparator.reverseOrder(). Java 8 stream APIs have introduced a lot of exciting features to write code in ...
๐ŸŒ
Quora
quora.com โ€บ How-can-we-rearrange-array-values-alphabetically-in-Java
How can we rearrange array values alphabetically in Java? - Quora
Answer (1 of 2): We can sort an array of string values in alphabetical order by using the sort() method of the Arrays class. This sorts the string array based on the values of the Unicode characters.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-sort-a-string-in-java-alphabetically-in-java
How to Sort a String in Java alphabetically in Java?
April 22, 2025 - Convert the sorted array to a String by passing it to the constructor of the String array. Following is an example to sort a string alphabetically - import java.util.Arrays; import java.util.Scanner; public class SortingString { public static void main(String args[]) { String str = "Hello welcome to Tutorialspoint"; char charArray[] = str.toCharArray(); Arrays.sort(charArray); System.out.println(new String(charArray)); } }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-program-to-sort-names-in-an-alphabetical-order
Java Program to Sort Names in an Alphabetical Order - GeeksforGeeks
July 23, 2025 - Using inbuilt Arrays.sort() method to sort the array. Print the Sorted Names in an Alphabetical Order. Below is the implementation of the above approach: Java ยท // Java Program to Sort Names in an Alphabetical Order import java.io.*; import ...
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ sorting-text-alphabetically-with-java-code-177cfc072947
Sorting Text Alphabetically with Java Code | Medium
July 26, 2025 - Learn how alphabetical sorting works in Java with Arrays.sort, Collections.sort, and custom comparators. Covers Unicode, case, and locale rules.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arrays_sort.asp
Java Arrays sort() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The sort() method sorts an array in ascending order. ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Java Tutorial | How to sort a string array in alphabetical order ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ sort a string in java
How to Sort a String In Java: A Step-by-Step Guide | upGrad
5 days ago - To sort string array in Java in alphabetical or ascending order, you can use the Arrays.sort() method from the Java standard library. This method provides a convenient way to sort an array in its natural order.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java-program-to-sort-an-array-in-alphabetical-order
Java Program to sort an array in alphabetical order
December 26, 2024 - This method belongs to Java.util package. This program sorts an array of strings (alphabets) in alphabetical order using the Arrays.sort() method.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java sorting โ€บ sort a string alphabetically in java
Sort a String Alphabetically in Java (with Examples)
July 11, 2023 - In case of strings, the natural order is the alphabetical order. So we need to perform the following pseudo steps: ... The following Java program demonstrates sorting the characters of a string using Stream.sorted() API. String string = "adcbgekhs"; String sortedString = Stream.of( string.split("") ) .sorted() .collect(Collectors.joining()); System.out.println(sortedString); // abcdeghks ยท The Arrays.sort() also does the same thing as Stream.sort() does.
๐ŸŒ
Scientech Easy
scientecheasy.com โ€บ home โ€บ blog โ€บ how to sort string in java
How to Sort String in Java - Scientech Easy
June 9, 2025 - Learn how to sort string in Java alphabetically in ascending or natural order and descending order using user defined logic and sort() method
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2018 โ€บ 10 โ€บ java-program-to-sort-strings-in-an-alphabetical-order
Java Program to Sort Strings in an Alphabetical Order
May 11, 2023 - Once we have all the strings stored in the string array, we are comparing the alphabets starting from the first alphabet of each string to get them sorted in the alphabetical order. import java.util.Scanner; public class JavaExample { public static void main(String[] args) { int count; String ...
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ java โ€บ how to lexicographically sort an array in java
How to Lexicographically Sort an Array in Java | Sentry
The simplest way to solve sorting an array is to use the Arrays.sort() method. This method works for sorting both primitive and object arrays in Java. Because strings are objects, the method we will use is Arrays.sort(Object[]). This sorting ...
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ java-program-to-sort-strings-in-alphabetical-order
Java Program to Sort Strings in Alphabetical Order
January 23, 2025 - package RemainingSimplePrograms; import java.util.Arrays; import java.util.Scanner; public class SortStringArrAlphabetically1 { private static Scanner sc; private static Scanner sc2; public static void main(String[] args) { sc = new Scanner(System.in); sc2 = new Scanner(System.in); System.out.print("Enter the Total Strings you enter = "); int Size = sc.nextInt(); String str[] = new String[Size]; System.out.format("Enter %d Strings one by one\n", Size); for(int i = 0; i < Size; i++) { str[i] = sc2.nextLine(); } Arrays.sort(str); System.out.format("\nAfter Sorting the String Alphabetically\n");
๐ŸŒ
Studytonight
studytonight.com โ€บ java-programs โ€บ java-program-to-sort-an-array-in-alphabetical-order
Java Program To Sort an Array in Alphabetical Order - Studytonight
March 5, 2021 - Enter the number of elements 5 Enter the String france india china germany italy [china, france, germany, india, italy] In this approach, we will sort an array in alphabetical order using Arrays.sort() and then again sort it in reverse order ...