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
String.toUpperCase()
Example
In the following program, we have taken a string and shall convert it to uppercase using String.toUpperCase() method.
Java Program
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.