Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Java reference

String.toUpperCase()

Returns a copy of the string with all letters in upper case.

Available since: Java 1.0

Syntax

public String toUpperCase()

Return value

StringA new string in upper case.

Examples

Converting to upper case:

void main() {
    String name = "anna";
    IO.println(name.toUpperCase());
    IO.println(name);
}

Output:

ANNA
anna

Capitalizing only the first letter:

void main() {
    String word = "java";
    String result = word.substring(0, 1).toUpperCase() + word.substring(1);
    IO.println(result);
}

Output:

Java

Notes

The method does not change the original string — store the result: name = name.toUpperCase();.

Without an argument it uses the system language rules. In the Turkish locale "i" becomes "İ", so for technical strings (keys, commands) write toUpperCase(Locale.ROOT).

See also

Related recipes

In the tutorial

  • String methods — The main String methods in Java: searching, substring, changing case, strip, replace, split, join, repeat and string checks.

Thanks for reading!

Donate to the site — we work hard for you.