LAST UPDATED: NOVEMBER 24, 2020
Java Character toTitleCase(char ch) Method
Java toTitleCase(char ch)
method is a part of Character
class. This method converts the specified character argument to titlecase using case mapping information from the UnicodeData file.
It must be noted that 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.
Syntax:
public static char toTitleCase(char ch)
Parameters:
The parameter passed is the character value to be converted to titlecase.
Returns:
Returns the titlecase value of the specified character.
Example 1:
Here, the characters are converted into equivalent titlecase characters.
public class StudyTonight
{
public static void main(String[] args)
{
char ch1 = 'F';
char ch2 = 'n';
char ch3 = '1';
char ch11 = Character.toTitleCase(ch1);
char ch22 = Character.toTitleCase(ch2);
char ch33 = Character.toTitleCase(ch3);
System.out.println("The titlecase character is : "+ch11);
System.out.println("The titlecase character is : "+ch22);
System.out.println("The titlecase character is : "+ch33);
}
}
The titlecase character is : F
The titlecase character is : N
The titlecase 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.toTitleCase(ch);
System.out.println("The titlecase character is : "+cc);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
Enter the character: s
The titlecase character is : S
************************************
Enter the character: U
The titlecase character is : U
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.