Java Character isJavaIdentifierStart()方法
Character.isJavaIdentifierStart(int codePoint) 是java中的一个内置方法,用于确定该字符(Unicode码位)是否可以作为Java标识符中的第一个字符。需要注意的是,当且仅当以下条件之一为真时,一个字符可以开始一个Java标识符。
- isLetter(ch)返回true
- getType(ch)返回LETTER_NUMBER
- ch是一个货币符号(如’$’)。
- ch是一个连接标点符号(如’_’)。
语法
public static boolean isJavaIdentifierStart(int codePoint)
参数: 参数codePoint是整数类型的,指的是要测试的字符(Unicode码位)。
返回值: Character类的isJavaIdentifierStart(int codePoint)方法,如果该字符可能开始一个Java标识符,则返回true;否则返回false。
下面的程序说明了Character.isJavaIdentifierStart()方法。
程序1 :
// Java program to illustrate
// Character.isJavaIdentifierStart() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create 2 int primitives c1, c2
int c1 = 0x0039, c2 = 0x004b, c3 = 0x0081;
// Assign isJavaIdentifierPart results of
// c1, c2 to boolean primitives bool1, bool2
boolean bool1 = Character.isJavaIdentifierStart(c1);
boolean bool2 = Character.isJavaIdentifierStart(c2);
boolean bool3 = Character.isJavaIdentifierStart(c3);
String str1 = "c1 may start a Java identifier is " + bool1;
String str2 = "c2 may start a Java identifier is " + bool2;
String str3 = "c3 may start a Java identifier is " + bool3;
// Print bool1, bool2 values
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
}
}
输出:
c1 may start a Java identifier is false
c2 may start a Java identifier is true
c3 may start a Java identifier is false
程序2
// Java program to illustrate
// Character.isJavaIdentifierStart() method
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create 2 int primitives c1, c2
int c1 = 0x0034, c2 = 0x005a;
// Assign isJavaIdentifierPart results of
// c1, c2 to boolean primitives bool1, bool2
boolean bool1 = Character.isJavaIdentifierStart(c1);
boolean bool2 = Character.isJavaIdentifierStart(c2);
String str1 = "c1 may start a Java identifier is " + bool1;
String str2 = "c2 may start a Java identifier is " + bool2;
// Print bool1, bool2 values
System.out.println(str1);
System.out.println(str2);
}
}
输出:
c1 may start a Java identifier is false
c2 may start a Java identifier is true
参考资料 : https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isJavaIdentifierStart(char)