Java – Convert a String to Uppercase

To convert a string to uppercase in Java, call toUpperCase() method on the string object. The method returns a new String object with the characters in the original string transformed to uppercase letters.

The syntax to convert a string to uppercase is

</>
Copy
String.toUpperCase()

1. Convert string to uppercase in Java using String.toUpperCase()

In the following program, we have taken a string and shall convert it to uppercase using String.toUpperCase() method.

Java Program

</>
Copy
public class Example {
	public static void main(String[] args){
		String str = "abcDefGH";
		String result = str.toUpperCase();
		System.out.println("Original String  : " + str);
		System.out.println("Uppercase String : " + result);
	}
}

Output

Original String  : abcDefGH
Uppercase String : ABCDEFGH

Conclusion

In this Java Tutorial, we learned how to convert a String to uppercase, using String.toUpperCase() method.