toUpperCase() String Example

java.lang.String class comes with toUpperCase() String method to convert all lowercase letters into uppercase in the string. After modification, a new string is returned with all the conversions.

The signature toUpperCase() String is given as defined in Java API.

  • public String toUpperCase(): Returns a new string after converting all the lowercase letters to uppercase letters in the given string.

In the following example, toUpperCase() String is used to convert all lowercase letters to uppercase letters in string oldString. Observe the screenshot, the original string oldString is not disturbed.

public class StringMethodDemo
 public static void main(String args[])
  String oldString = "Hello World How Do You Do";

  String newString = oldString.toUpperCase();

  System.out.println("Original string before conversion: " + oldString);
  System.out.println("\nNew string after conversion: " + newString);

toUpperCase() String
Output screenshot of toUpperCase() String Example

Pass your comments and suggestions on this tutorial "toUpperCase() String Example".

Leave a Comment

Your email address will not be published.