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代碼點)。
返回值:如果字符可以啟動Java標識符,則Character類的isJavaIdentifierStart(int codePoint)方法返回true。否則為假。
以下示例程序旨在說明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)
相關用法
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java.math.BigInteger.modInverse()用法及代碼示例
- Java Clock tickMinutes()用法及代碼示例
- Java Java.math.BigInteger.probablePrime()用法及代碼示例
- Java Java.util.ArrayList.addall()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 Character.isJavaIdentifierStart() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。