Java toUpperCase Method

The Java toUpperCase Method is one of the Java String Methods, which is useful to convert the given string into Uppercase letters. In this article, we will show how to use String toUpperCase in Java Programming language with example. The syntax of the string.toUpperCase in Java Programming language is as shown below.

Java toUpperCase Method syntax

Java provides two different methods to convert the specified string into Uppercase letters. The following method will not accept any parameters and convert all the characters in a string to uppercase using the rule of the default locale.

public String toUpperCase(); // It will return String 

//In order to use in program
String_Object.toUpperCase()

The following function will accept Locale value as the parameter and convert all the characters in a string to uppercase using the user-specified locale variable.

public String toUpperCase(Locale locale); // It will return String 

//In order to use in program
String_Object.toUpperCase(Locale locale)
  • String_Object: Please specify the valid String Object.
  • locale: Please specify the Locale you want to use while converting the String_Object characters to Uppercase. For example, English, Turkish, Latin, etc.

Java to UpperCase Method Example

The Java string toUpperCase method converts the characters within a string to uppercase. This program will help to understand the string toupperCase method.

package StringFunctions;

public class ToUpperCaseMethod {
 public static void main(String[] args) {
 String str = "Java ProgramminG Tutorial at Tutorial GateWay";
 
 String str1 = str.toUpperCase();
 String str2 = "Java Programming Language".toUpperCase();
 String str3 = "PRogramming WOrld".toUpperCase();
 String str4 = "TrY tO ReAd ThIs SenTEnCe".toUpperCase();
 
 System.out.println( "New Uppercase String = " + str1);
 System.out.println( "New Uppercase String = " + str2);
 System.out.println( "New Uppercase String = " + str3);
 System.out.println( "New Uppercase String = " + str4);
 }
}
Java toUpperCase Method 1

The following statements will convert the previously declared String into uppercase and assign it to Str1. Next, we used the toUpperCase String Method directly on string data.

String str1 = str.toUpperCase();
String str2 = "Java Programming Language".toUpperCase();
String str3 = "PRogramming WOrld".toUpperCase();
String str4 = "TrY tO ReAd ThIs SenTEnCe".toUpperCase();

The following Java System.out.println statements will print the output.

System.out.println( "New Uppercase String = " + str1);
System.out.println( "New Uppercase String = " + str2);
System.out.println( "New Uppercase String = " + str3);
System.out.println( "New Uppercase String = " + str4);