.toUpperCase()
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.javapublic 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 WorldHELLO WORLD
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly17 hours