LAST UPDATED: NOVEMBER 24, 2020
Java Character toTitleCase(int codePoint) Method
Java toTitleCase(int codePoint)
method is a part of Character
class. This method converts the specified Unicode code point character argument to titlecase using case mapping information from the UnicodeData file.
It must be noted that if a code point 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.
Syntax:
public static char toTitleCase(int codePoint)
Parameters:
The parameter passed is the Unicode code point character value to be converted to titlecase.
Returns:
Returns the titlecase value of the specified code point character.
Example 1:
Here, the characters are converted into equivalent titlecase characters.
public class StudyTonight
{
public static void main(String[] args)
{
int cp1 = 78;
int cp2 = 102;
int cp3 = 66;
int cp4 = 48;
int cp5 = 1232;
char ch1 = Character.toTitleCase(cp1);
char ch2 = Character.toTitleCase(cp2);
char ch3 = Character.toTitleCase(cp3);
char ch4 = Character.toTitleCase(cp4);
char ch5 = Character.toTitleCase(cp5);
System.out.println("The titlecase character is :"+ch1);
System.out.println("The titlecase character is :"+ch2);
System.out.println("The titlecase character is :"+ch3);
System.out.println("The titlecase character is :"+ch4);
System.out.println("The titlecase character is :"+ch5);
}
}
The titlecase character is :N
The titlecase character is :F
The titlecase character is :B
The titlecase character is :0
The titlecase character is :?
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 Unicode codepoint: ");
Scanner sc = new Scanner(System.in);
int cp = sc.nextInt();
char cc = Character.toTitleCase(cp);
System.out.println("The titlecase character is : "+cc);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
Enter the Unicode codepoint: 99
The titlecase character is : C
***************************************
Enter the Unicode codepoint: 110
The titlecase character is : N
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.