LAST UPDATED: NOVEMBER 24, 2020
Java Character isTitleCase(char ch) Method
Java isTitleCase(char ch)
is a part of Character
class. This method is used to check whether the specified character is a Titlecase character or not.
This method does not support supplementary characters. A character is a title case character if its general category type, provided by Character.getType(ch)
, is TITLECASE_LETTER
.
These are some of the Unicode characters for which this method returns true
:
LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON
LATIN CAPITAL LETTER L WITH SMALL LETTER J
LATIN CAPITAL LETTER N WITH SMALL LETTER J
LATIN CAPITAL LETTER D WITH SMALL LETTER Z
Syntax:
public static boolean isTitleCase(char ch)
Parameters:
The parameter passed is the character to be checked whether it is the title case or not.
Returns:
Returns the boolean value true
if the specified character is a title case character else return false
.
Example 1:
Here, the characters are checked whether they are title case characters or not.
public class StudyTonight
{
public static void main(String[] args)
{
char ch1 = 'N';
char ch2 = 'd';
char ch3 = '\u01f2';
char ch4 = '0';
char ch5 = '7';
boolean b1 = Character.isTitleCase(ch1);
boolean b2 = Character.isTitleCase(ch2);
boolean b3 = Character.isTitleCase(ch3);
boolean b4 = Character.isTitleCase(ch4);
boolean b5 = Character.isTitleCase(ch5);
System.out.println(ch1 +" is title case character??: "+b1);
System.out.println(ch2 +" is title case character??: "+b2);
System.out.println(ch3 +" is title case character??: "+b3);
System.out.println(ch4 +" is title case character?? : "+b4);
System.out.println(ch5 +" is title case character??: "+b5);
}
}
N is title case character??: false
d is title case character??: false
? is title case character??: true
0 is title case character?? : false
7 is title case character??: false
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);
boolean b = Character.isTitleCase(ch);
System.out.println(ch + " is title case??: "+b);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
Enter the character: R
R is title case??: false
***************************
Enter the character: 1
1 is title case??: false
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.