Library contents

Java String.toUpperCase

Convert a three-letter airport code to uppercase before comparing it with a timetable.

A simple example

String.toUpperCase

  1. Start with "ab"
  2. Do this Convert to uppercase
  3. Result "AB"
Both ASCII letters acquire their uppercase forms.
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("ab".toUpperCase(java.util.Locale.ROOT));
    }
}
Output
AB

Syntax

Java syntax
label.toUpperCase(java.util.Locale.ROOT)
JDK 21 method signatures (2)
public String toUpperCase(Locale locale)
public String toUpperCase()
Run these examples in Java

Save one example at a time as Main.java. Use JDK 21.

java Main.java

Standardize an airport code

A travel desk receives airport codes in mixed case from several forms. Convert the code to the required display case so it can be compared with the label on the boarding pass.

From the programString label = "maa"
ResultMAA
Main.java

class Main {
    public static void main(String[] args) throws Exception {
        String label = "maa";
        System.out.println(label.toUpperCase(java.util.Locale.ROOT));
    }
}
Output
MAA

The lowercase letters become MAA, the code displayed on the ticket.

Advertisements

Normalize a printed airport code

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 airport = "maa"
ResultMAA
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        String airport = "maa";
        System.out.println(airport.toUpperCase(java.util.Locale.ROOT));
    }
}
Output
MAA

A locale-independent transformation suits this ASCII airport identifier.

Prepare a German street 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 street = "Straße"
ResultSTRASSE
Main.java
class Main {
    public static void main(String[] args) throws Exception {
        String street = "Straße";
        System.out.println(street.toUpperCase(java.util.Locale.GERMAN));
    }
}
Output
STRASSE

The sharp s expands into two letters, so a fixed-width label may need more space.

What to watch for

Airport codes use ASCII. Names and other human text may need language-specific case handling.

Documentation for String.toUpperCase