这个 性格isJavaIdentifierStart(int代码点) 是java中的一种内置方法,用于确定是否允许字符(Unicode代码点)作为java标识符中的第一个字符。需要注意的是,当且仅当下列条件之一为真时,一个字符可以启动Java标识符:
null
- isLetter(ch)返回true
- getType(ch)返回字母_编号
- ch是一种货币符号(如“$”)
- ch是一个连接的标点符号(例如“_”)。
语法:
public static boolean isJavaIdentifierStart(int codePoint)
参数: 参数 代码点 是整数类型,指要测试的字符(Unicode代码点)。
返回值: 如果字符可以启动Java标识符,Character类的isJavaIdentifierStart(int codePoint)方法将返回true;否则就错了。
下面的程序说明了这个角色。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(字符)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END