Library contents

Java String.toLowerCase

Return a lowercase version of a string using a specified locale or the process default.

A simple example

String.toLowerCase

  1. Start with "AB"
  2. Do this Convert to lowercase
  3. Result "ab"
Each uppercase ASCII letter has a lowercase counterpart.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("AB".toLowerCase(java.util.Locale.ROOT));
    }
}
Output
ab

Syntax

Java 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.java

Normalize 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.

From the programString tag = "GREEN-TEA"
Resultgreen-tea
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        String tag = "GREEN-TEA";
        System.out.println(tag.toLowerCase(java.util.Locale.ROOT));
    }
}
Output
green-tea

The same machine tag is produced regardless of the user’s default locale.

Advertisements

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.

From the programString city = "ISTANBUL"
Resultıstanbul
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        String city = "ISTANBUL";
        System.out.println(city.toLowerCase(java.util.Locale.forLanguageTag("tr")));
    }
}
Output
ı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?

GivenNC-17
Worked resultnc-17

What to watch for

For machine identifiers use Locale.ROOT. Human-language casing can depend on the locale and can change length.

Documentation for String.toLowerCase