Java String.toUpperCase
Convert a three-letter airport code to uppercase before comparing it with a timetable.
A simple example
String.toUpperCase
- Start with "ab"
- Do this Convert to uppercase
- Result "AB"
class Main {
public static void main(String[] args) throws Exception {
System.out.println("ab".toUpperCase(java.util.Locale.ROOT));
}
}
AB
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.javaStandardize 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.
class Main {
public static void main(String[] args) throws Exception {
String label = "maa";
System.out.println(label.toUpperCase(java.util.Locale.ROOT));
}
}
MAA
The lowercase letters become MAA, the code displayed on the ticket.
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.
class Main {
public static void main(String[] args) throws Exception {
String airport = "maa";
System.out.println(airport.toUpperCase(java.util.Locale.ROOT));
}
}
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.
class Main {
public static void main(String[] args) throws Exception {
String street = "Straße";
System.out.println(street.toUpperCase(java.util.Locale.GERMAN));
}
}
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.