Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

String.toUpperCase — converting to uppercase

String.toUpperCase returns uppercase text. The chosen Locale affects the result; Locale.ROOT provides language-neutral rules.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

public String toUpperCase()
public String toUpperCase(Locale locale)

String.toUpperCase returns uppercase text without modifying the original String. Keep the returned value if you need the result.

toUpperCase() uses Locale.getDefault(). The toUpperCase(Locale locale) overload lets you choose rules explicitly. Use Locale.ROOT for language-neutral text; choose the appropriate locale for user-facing text.

Unicode conversion can change length: ß becomes SS. In Turkish, i becomes İ, not I. The example demonstrates both differences and preservation of the original.

Examples

import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        String text = "stra\u00dfe";
        System.out.println(text.toUpperCase(Locale.ROOT));
        System.out.println(text);
        System.out.println("title".toUpperCase(Locale.forLanguageTag("tr")));
    }
}

Result

STRASSE
straße
TİTLE

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources