Java

What is Character.toUpperCase() in Java?

Java is case-sensitive like most programming languages. Even a small change in the name signifies that the objects are distinct. Moreover, programmers follow naming standards to maintain consistency. For instance, variables, such as “car” are defined in lowercase, while “CLASSES” are in uppercase. However, if you want to convert a string value to uppercase, utilize the “toUpperCase” method in your program.

This write-up will state the method character.toUpperCase() in Java.

What is Character.toUpperCase() in Java?

The “toUpperCase()” method in Java is utilized for converting the element or characters in uppercase. However, it can not modify the actual string.

How to Utilize the “toUpperCase()” in Java?

To use the “.toUpperCase()” method, check out the given syntax:

string.toUpperCase()

Here, the “toUpperCase()” method will convert the string into UpperCase.

Example 1: Convert LowerCase String to UpperCase in Java

To convert the lowercase string to uppercase, add the text by defining the string. To do so, follow the below-listed instructions:

  • First, initialize a variable to add the text in the Java file. In this case, the “txt” variable is utilized.
  • Next, the “.toUpperCase()” method converts the characters into uppercase.
  • System.out.println()” is utilized to display the output on the console:
String txt = "linuxhint ltd uk";

System.out.println(txt.toUpperCase());

It can be observed that all of the characters have been converted into UpperCase:

Example 2: Convert CamelCase to UpperCase in Java

You can also convert the lowercase as well as camelcase letters into the uppercase. To do so, the value of the initialize the variable is set as camel case:

String txt = "Linuxhint Tutorial Website";

System.out.println(txt.toUpperCase());

Output

That’s all about converting characters to uppercase in Java.

Conclusion

In Java, you can use the “toUpperCase()” method for the purpose of converting elements or multiple strings in capital letters. This method can also be utilized for converting camelcase characters into uppercase. This post demonstrated the usage of the Character.toUpperCase() method in Java.

About the author

Hafsa Javed