In this tutorial, you will learn about String toUpperCase() method, its syntax, and usage with examples.
Java String toUpperCase() method
In Java, String toUpperCase() method converts all the characters in the string to upper case.
Test input string
</>
Copy
Hello World
Upper case string
</>
Copy
HELLO WORLD
Syntax of toUpperCase()
The syntax to call String toUpperCase() method in Java is
</>
Copy
string.toUpperCase()
toUpperCase() method takes no parameters.
toUpperCase() returns value of String type.
Examples
1. toUpperCase() – Convert the string “Hello World” to upper case in Java
In this example, we take a string value of "Hello World"
in str, and convert this string to upper case using String toUpperCase() method.
Java Program
</>
Copy
public class Main {
public static void main(String[] args) {
String str = "Hello World";
String upperCaseStr = str.toUpperCase();
System.out.println("Given string : " + str);
System.out.println("Uppercase string : " + upperCaseStr);
}
}
Output
Given string : Hello World
Uppercase string : HELLO WORLD
Conclusion
In this Java String Methods tutorial, we have seen about String toUpperCase() method in Java, its syntax, and how to use String toUpperCase() method in Java programs with the help of examples.