In this section, we will learn what the String toUpperCase() method is and how to use it in Java.
What is Java String toUpperCase() Method?
The `toUpperCase()` method is used to turn all the letters of a string value into uppercase and return a new String object as a result.
Note: this method does not change the original string value but returns a new one as a result.
Java toUpperCase() Method Syntax:
public String toUpperCase()
toUpperCase() Method Parameters:
This method does not take an argument.
toUpperCase() Method Return Value:
The return value of this method is a new string value with the same content as the target string value but converted in uppercase letters.
toUpperCase() Method Exceptions:
This method does not throw an exception.
Example: using String toUpperCase() method
public class Simple { public static void main(String[] args) { String s1 = "be kind to one another"; String res = s1.toUpperCase(); System.out.println(res); } }
Output:
BE KIND TO ONE ANOTHER
Convert Uppercase to Lowercase
On the contrary, to the `toUpperCase()` method we have `toLowerCase()` method.
This method is used to convert an uppercase string value into lowercase.
Example: converting uppercase string value to lowercase
public class Simple { public static void main(String[] args) { String s1 = "BE KIND TO ONE ANOTHER"; String res = s1.toLowerCase(); System.out.println(res); } }
Output:
be kind to one another