.toUpperCase()

Anonymous contributor's avatar
Anonymous contributor
Published Feb 13, 2023
Contribute to Docs

The .toUpperCase() method converts all lowercase letters of a string to uppercase and returns a new string.

Syntax

string.toUpperCase();

Where string is the string in which all lowercase letters are converted to uppercase. The .toUpperCase() method returns a new string consisting of the upper case form of the letters in the original string. To use the new upper case string, the returned string must be assigned to a variable.

Example

The following example applies the .toUpperCase() method to the given text:

// MyClass.java
public class MyClass {
public static void main(String[] args) {
String text = "Hello World";
String textUp = text.toUpperCase();
System.out.println(text);
System.out.println(textUp);
}
}

This will print the following output:

Hello World
HELLO WORLD

All contributors

Contribute to Docs

Learn Java on Codecademy