In this section, we will learn what the Character toUpperCase() method is and how to use it in Java.
What is Java Character toUpperCase() Method?
The `toUpperCase()` method is used to return the uppercased letter of the character that we set as the argument of the method.
Java toUpperCase() Method Syntax:
static char toUpperCase(char ch)
toUpperCase() Method Parameters:
The method takes one argument, and that is the character we want to uppercase.
toUpperCase() Method Return Value:
The return value of this method is the uppercase version of the character that we set as its argument.
Note: if the character is already an uppercase one, this method will return that with no changes.
Also, the type of the character is “char”.
Example: using Character toUpperCase() method
public class Simple { public static void main(String args[]) { String s = "You Never Know What Will Happen Tomorrow!"; char[] chars = new char[s.length()]; int i = 0; for (char c: s.toCharArray()){ chars[i] = Character.toUpperCase(c); i++; } String res = String.valueOf(chars); System.out.println(res); } }
Output:
YOU NEVER KNOW WHAT WILL HAPPEN TOMORROW!