Signup/Sign In
LAST UPDATED: NOVEMBER 24, 2020

Java Character toUpperCase(char ch) Method

Java toUpperCase(char ch) method is a part of Character class. This method converts the given character argument to the uppercase using case mapping information which is provided by the Unicode Data file.

It must be noted that Character.isUpperCase(Character.toUpperCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or ideographs.

Syntax:

public static char toUpperCase(char ch) 

Parameters:

The parameter passed is the character value to be converted.

Returns:

Returns the uppercase equivalent of the specified character, if any; otherwise, the character itself.

Example 1:

Here, the specified characters are converted into its equivalent uppercase characters.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		char ch1 = 'F';  
		char ch2 = 'n';
		char ch3 = '1';

		char ch11 = Character.toUpperCase(ch1);  
		char ch22 = Character.toUpperCase(ch2);
		char ch33 = Character.toUpperCase(ch3);

        System.out.println("The uppercase character is : "+ch11);  
		System.out.println("The uppercase character is : "+ch22); 
		System.out.println("The uppercase character is : "+ch33); 
	}  
}


The uppercase character is : F
The uppercase character is : N
The uppercase character is : 1

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner; 
public class StudyTonight
{  
	public static void main(String[] args)
	{  
		try
		{
			System.out.print("Enter the character: ");  
			Scanner sc = new Scanner(System.in);         
			char ch = sc.next().charAt(0);  
			char cc = Character.toUpperCase(ch);
			System.out.println("The uppercase character is : "+cc);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the character: g
The uppercase character is : G
**************************************
Enter the character: 7
The uppercase character is : 7

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.



About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.