Java.lang.Character.toTitleCase() Method
Description
The java.lang.Character.toTitleCase(char ch) converts the character argument to titlecase using case mapping information from the UnicodeData file.
If a character has no explicit titlecase mapping and is not itself a titlecase char according to UnicodeData, then the uppercase mapping is returned as an equivalent titlecase mapping. If the char argument is already a titlecase char, the same char value will be returned.
Note that Character.isTitleCase(Character.toTitleCase(ch)) does not always return true for some ranges of characters.
Declaration
Following is the declaration for java.lang.Character.toTitleCase() method
public static char toTitleCase(char ch)
Parameters
ch - the character to be converted
Return Value
This method returns the titlecase equivalent of the character, if any; otherwise, the character itself.
Exception
NA
Example
The following example shows the usage of lang.Character.toTitleCase() 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 = 'p';
ch2 = '+';
// assign titlecase of ch1, ch2 to ch3, ch4
ch3 = Character.toTitleCase(ch1);
ch4 = Character.toTitleCase(ch2);
String str1 = "Titlecase of " + ch1 + " is " + ch3;
String str2 = "Titlecase 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:
Titlecase of p is P Titlecase of + is +