Java.lang.Character.toUpperCase() Method
Advertisements
Description
The java.lang.Character.toUpperCase(char ch) converts the character argument to uppercase using case mapping information from the UnicodeData file.
Note that Character.isUpperCase(Character.toUpperCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or ideographs.
Declaration
Following is the declaration for java.lang.Character.toUpperCase() method
public static char toUpperCase(char ch)
Parameters
ch - the character to be converted
Return Value
This method returns the uppercase equivalent of the character, if any; otherwise, the character itself.
Exception
NA
Example
The following example shows the usage of lang.Character.toUpperCase() method.
package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
// create 4 char primitives
char ch1, ch2, ch3, ch4;
// assign values to ch1, ch2
ch1 = '4';
ch2 = 'q';
// assign uppercase of ch1, ch2 to ch3, ch4
ch3 = Character.toUpperCase(ch1);
ch4 = Character.toUpperCase(ch2);
String str1 = "Uppercase of " + ch1 + " is " + ch3;
String str2 = "Uppercase of " + ch2 + " is " + ch4;
// print ch3, ch4 values
System.out.println( str1 );
System.out.println( str2 );
}
}
Let us compile and run the above program, this will produce the following result:
Uppercase of 4 is 4 Uppercase of q is Q