Java String.toLowerCase
Return a lowercase version of a string using a specified locale or the process default.
A simple example
String.toLowerCase
- Start with "AB"
- Do this Convert to lowercase
- Result "ab"
class Main {
public static void main(String[] args) throws Exception {
System.out.println("AB".toLowerCase(java.util.Locale.ROOT));
}
}
ab
Syntax
public String toLowerCase(Locale locale)
JDK 21 method signatures (2)
public String toLowerCase(Locale locale)
public String toLowerCase()Run these examples in Java
Save one example at a time as Main.java. Use JDK 21.
java Main.javaNormalize a product tag
Two terminals can enter the same short label with different capitalization or padding. Normalize the incoming spelling before lookup so the stored identifiers can follow a consistent convention.
class Main {
public static void main(String[] args) throws Exception {
String tag = "GREEN-TEA";
System.out.println(tag.toLowerCase(java.util.Locale.ROOT));
}
}
green-tea
The same machine tag is produced regardless of the user’s default locale.
Lowercase a Turkish city label
A local address directory displays names in the spelling appropriate to the reader. Choose the intended case conversion and examine how letters outside English behave before saving the display label.
class Main {
public static void main(String[] args) throws Exception {
String city = "ISTANBUL";
System.out.println(city.toLowerCase(java.util.Locale.forLanguageTag("tr")));
}
}
ıstanbul
Turkish casing turns the initial capital I into a dotless lowercase letter.
Read a parcel sorting code
The depot scans a parcel marked NC-17. The search index stores the complete identifier in lowercase. Which key goes into the index?
What to watch for
For machine identifiers use Locale.ROOT. Human-language casing can depend on the locale and can change length.