java.lang.String toUpperCase()

Description :

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

Method Syntax :

public String toUpperCase()

Parameter Input :

DataType Parameter Description
N/A N/A N/A

Method Returns :

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

Compatibility Version :

Since the beginning

Exception :

N/A

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.

Java Code Example :

This example source code demonstrates the use of toUpperCase() method of String class.

package com.javatutorialhq.java.tutorial.string;

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

public class StringUpperCaseDemo {

	public static void main(String[] args) {
		// declaring our String object
		String name = "AlberT einstein";
		// changing to lower case
		String upperCaseName = name.toUpperCase();
		System.out.println("Name in Upper Case: "+upperCaseName);

	}

}

Sample Output :

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

string toUpperCase method example

string toUpperCase method example

Exception Scenario :

N/A

Similar Method :

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

Suggested Reading List :