String.compareTo might or might not be what you need.

Take a look at this link if you need localized ordering of strings.

Answer from Buhb on Stack Overflow
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › compareTo
Java String compareTo() - Compare Strings Alphabetically | Vultr Docs
May 15, 2025 - The compareTo() method in Java is a crucial function from the String class that facilitates the alphabetical comparison of two strings. This method is commonly used in Java string comparison, especially for sorting strings, determining ...
🌐
Mkyong
mkyong.com › home › java › java string compareto() examples
Java String compareTo() examples - Mkyong.com
January 24, 2022 - The "a" is lexicographically precedes the argument string "c"; it returns a negative integer. In simple words, for lexicographical or alphabetical order, "a" comes before the "c" and returns a negative integer.
🌐
W3Docs
w3docs.com › java
Comparing strings by their alphabetical order
To compare strings by their alphabetical order in Java, you can use the compareTo() method of the String class.
🌐
Coderanch
coderanch.com › t › 702035 › java › compare-strings-find-alphabetically-Java
How to compare two strings and find which is first alphabetically in Java? Built-in Method? (Java in General forum at Coderanch)
If you want to know which of two strings is larger, you can use String.compareTo(). ... Okay, thank you so much! ... If you go through the Java™ Tutorials, you will find lots aout sorting. You might also find that there is a Comparator already provided in the String class for sorting a before B.
🌐
Quora
quora.com › How-do-you-compare-strings-alphabetically-in-Java
How to compare strings alphabetically in Java - Quora
Answer (1 of 3): “German phone book, case‑insensitive, accent‑insensitive, numeric”, using standard Java SE 1.1 java.text.* APIs. [code]import java.text.Collator; import java.text.CollationKey; import java.util.Locale; public class GermanPhonebook { private static final Collator COLLATOR; ...
🌐
Delft Stack
delftstack.com › home › howto › java › java compare strings alphabetically
How to Compare Strings Alphabetically in Java | Delft Stack
February 2, 2024 - If we want to compare strings alphabetically using a custom comparator, we can create our comparator class and specify the custom comparison logic. We will use the following syntax in our next code example: import java.util.Comparator; public ...
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › java › how to compare strings in java
How to compare strings in Java | Sentry
public class Main { public static ... than another string (that is, whether it comes before or after alphabetically), use String.compareTo()....
🌐
Jazz Community Site
jazz.net › dxl › html › 1885 - Comparing strings alphabetically.html
Comparing strings alphabetically
This seems like a very basic question to me, but I have not been able to find a clear answer in the dxl reference manual. I am wishing to compare two strings alphabetically. I was thinking about creating a function that uses the ASCII values of each character in the strings to compare them ...
🌐
Coderanch
coderanch.com › t › 640534 › java › Sort-String-list-Alphabetically-compareTo
Sort String list Alphabetically with compareTo method/if else statements, logic errors (Beginning Java forum at Coderanch)
I would do the following: 1. Convert the input Strings into a List or an Array 2. Iterate over the array, take the first element and compare it against all the next element in the Array 3. If the comparison results in the first element being the smallest, I will collect that into another sorted collection 4.
🌐
Reddit
reddit.com › r/learnprogramming › how to compare two strings alphabetically without using "compareto"
How to compare two strings alphabetically without using "compareTo" : r/learnprogramming
November 18, 2017 - Without using compareTo, is there a way to compare string values to sort alphabetically ... There are other comparable methods you can use, but compareTo is what you should be using for that sort of thing. If it's an array of strings you can just use Arrays.sort(). More replies More replies More replies More replies ... What language are you talking about? Might be useful to add important details like that. ... I am sorry, I forgot that. It's java
🌐
Guru99
guru99.com › home › java tutorials › java string manipulation with example
Java String Manipulation with EXAMPLE
November 26, 2024 - In Java Strings provides a lot of methods for string manipulation. Learn some important String class methods i.e. Length, indexOf, charAt, CompareTo, Contain, endsWith, replaceAll, replaceFirst, tolowercase, touppercase
🌐
GeeksforGeeks
geeksforgeeks.org › java › compare-two-strings-lexicographically-in-java
Compare two strings lexicographically in Java - GeeksforGeeks
July 11, 2024 - Each character of both the strings is converted into a Unicode value for comparison. ... // Java program to show how to compare Strings // using library function public class Test { public static void main(String[] args) { String s1 = "Ram"; String s2 = "Ram"; String s3 = "Shyam"; String s4 = "ABC"; System.out.println(" Comparing strings with compareTo:"); System.out.println(s1.compareTo(s2)); System.out.println(s1.compareTo(s3)); System.out.println(s1.compareTo(s4)); } }
🌐
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 - The idea is to compare the strings on the basis of their unicode and swap them in accordance with the returned int value based on the comparison between the two strings using compareTo() method.
🌐
Coderanch
coderanch.com › t › 399908 › java › Comparing-character-strings-alphabetically
Comparing two-character strings alphabetically. (Beginning Java forum at Coderanch)
Well, here is one solution: put ... edited by: John Smith ] ... Can your database query just order by this field? Failing that, look at the compareTo() method....
🌐
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.
🌐
Sololearn
sololearn.com › en › Discuss › 1691307 › how-to-know-if-the-first-letter-of-a-string-is-alphabetically-greater-than-the-first-letter-of
How to know if the first letter of a String is alphabetically greater than the first letter of another String? | Sololearn: Learn to code for FREE!
Leo Hunter But you have to be careful: first.charAt (0) > second.charAt (0) means not that you compare the letters itself, you compare the ascii values of these letters. A > b --> true (65 < 98) a < B --> false (97 > 66) If you have capital letters in your String, you can use this method: YourString.toLowerCase (); ... did old java not have an easier way?