java.lang.String toUpperCase()

Description :

This java tutorial shows how to use the toUpperCase(Locale locale) method of String class of java.lang package. This method returns a new String object which is the original string in upper case with respect to the Locale method parameter. The toUpperCase(Locale) method of String class simply used in conversion of String into upper case.

Method Syntax :

public String toUpperCase(Locale locale)

Parameter Input :

DataType Parameter Description
Locale locale This parameter serves as a rule in changing the characters in upper case

Method Returns :

This String toUppercase(Locale locale) method returns a new String object which is just the String equivalent in upper case.

Compatibility Version :

Requires Java 1.1 and up

Exception :


Discussion :

Since a String can never be changed once instantiated, thus a new string object variable is required to hold the new string during the conversion to uppercase. This method is helpful especially if we are comparing and storing data which comes from different systems. And also this is naturally being used to compare two fields which came from two different sources and expected that the values are not normalized.

Java Code Example :

This example source code demonstrates the use of toUpperCase() method of String class with respect to the locale being used. The locale comes from the value of parameter ENGLISH of Locale class.


import java.util.Locale;

 * Example source code for toUpperCase(Locale locale) method of String class

public class StringUpperCaseDemo {

	public static void main(String[] args) {

		// declaring our String object
		String name = "AlberT einstein";
		//declaring the locale object to be used
		Locale locale = Locale.ENGLISH;
		// changing to lower case
		String upperCaseName = name.toUpperCase(locale);
		System.out.println("Name in Upper Case: "+upperCaseName);



Sample Output :

Running the toUpperCase(Locale locale) method example source code of String class will give you the following output

string toUpperCase method example

string toUpperCase method example

Exception Scenario :


Similar Method :

  • java.lang.String toLowerCase()
  • java.lang.String toLowerCase(Locale locale)

Suggested Reading List :

References :