LAST UPDATED: NOVEMBER 24, 2020
Java Character isUnicodeIdentifierStart(int codePoint) Method
Java isUnicodeIdentifierStart(int codePoint)
is a part of Character
class. This method is used to check whether the specified Unicode codepoint character is allowed as the first character in a Unicode identifier or not.
This method also supports supplementary characters. A character may start a Unicode identifier if and only if one of the following conditions is true:
isLetter(ch)
returns true
getType(ch)
returns LETTER_NUMBER
.
Syntax:
public static boolean isUnicodeIdentifierStart(int codePoint)
Parameters:
The parameter passed is the Unicode codepoint character to be checked whether it is allowed as a start character in the Unicode identifier.
Returns:
Returns the boolean value true
if the specified Unicode codepoint character is allowed as the first character of Unicode identifier else return false
.
Example 1:
Here, the characters are checked whether they are allowed as start character of Unicode identifier or not.
public class StudyTonight
{
public static void main(String[] args)
{
int cp1 = 32;
int cp2 = 60;
int cp3 = 119;
int cp4 = 93;
int cp5 = 1232;
boolean b1 = Character.isUnicodeIdentifierStart(cp1);
boolean b2 = Character.isUnicodeIdentifierStart(cp2);
boolean b3 = Character.isUnicodeIdentifierStart(cp3);
boolean b4 = Character.isUnicodeIdentifierStart(cp4);
boolean b5 = Character.isUnicodeIdentifierStart(cp5);
System.out.println((char)cp1 +" is a start Unicode identifier??:: "+b1);
System.out.println((char)cp2 +" is a start Unicode identifier??:: "+b2);
System.out.println((char)cp3 +" is a start Unicode identifier??:: "+b3);
System.out.println((char)cp4 +" is a start Unicode identifier??:: "+b4);
System.out.println((char)cp5 +" is a start Unicode identifier??:: "+b5);
}
}
is a start Unicode identifier??:: false
< is a start Unicode identifier??:: false
w is a start Unicode identifier??:: true
] is a start Unicode identifier??:: false
? is a start Unicode identifier??:: true
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 character: ");
Scanner sc = new Scanner(System.in);
int cp = sc.nextInt();
boolean b = Character.isUnicodeIdentifierStart(cp);
System.out.println((char)cp + " is a start Unicode identifier??: "+b);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
Enter the Unicode character: 67
C is a start Unicode identifier??: true
*******************************************
Enter the Unicode character: 55
7 is a start Unicode identifier??: 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.