toUpperCase() Java - How to convert lowercase to uppercase
toUpperCase() in Java
With the help of the toUpperCase() method, you can make letters capital. For example, the string with the text "Coding is fun" will be converted into "CODING IS FUN."
Syntax
1 |
public String toUpperCase() |
How To Call the Method:
1 |
String result = str.toUpperCase(); |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public class Test { public static void main(String args[]){ String str = "I love Java"; String result = str.toUpperCase(); System.out.println("Result: " + result); str = "1 and 2 and 3"; result = str.toUpperCase(); System.out.println("Result: " + result); str = "VERTEX"; result = str.toUpperCase(); System.out.println("Result: " + result); } } |
If you run this code on your computer, you will see the following in the console:
Commentary:
As you see, we have applied the method called toUpperCase() to 3 different Strings:
- "I love Java"
- "1 and 2 and 3"
- "VERTEX"
As a result,
- "I love Java" was converted into "I LOVE JAVA";
- "1 and 2 and 3" was converted into "1 AND 2 AND 3 ".
- "VERTEX" initially was written in capital letters, that's why the method returned the same result - "VERTEX".
* The method toUpperCase() also has another realization - with the parameter Locale. Later on we will write a separate article on this.
You can find more articles in our Java Tutorial for Beginners.