Java .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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours