java.lang.Character.isUnicodeIdentifierPart()是java中的一個內置方法,該方法確定指定字符是否可能是第一個字符以外的Unicode標識符的一部分。
當且僅當以下陳述之一為真時,字符才可能是Unicode標識符的一部分:
- 它是連接的標點符號(例如“ _”)
- 這是一個數字
- 這是一封信
- 這是一個組合標記
- isIdentifierIgnorable為此字符返回true。
- 它是一個數字字母(例如羅馬數字字符)
- 這是一個非間距標記
用法:
public static boolean isUnicodeIdentifierPart(datatype character)
參數:該函數接受一個強製性參數字符。此參數可以是int或char數據類型。它指定要測試的字符。
返回值:如果字符可能是Unicode標識符的一部分,則此方法返回true,否則返回false。
以下程序說明了java.lang.Character.isUnicodeIdentifierPart()方法:
示例1:當傳遞的參數是字符時。
// Code to illustrate the Character.isUnicodeIdentifierPart()
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Creating character primitives
char char1 = '-';
char char2 = '7';
char char3 = 'g';
boolean bool1 = Character.isUnicodeIdentifierPart(char1);
boolean bool2 = Character.isUnicodeIdentifierPart(char2);
boolean bool3 = Character.isUnicodeIdentifierPart(char3);
String str1 = " Is " + char1 + " a part of Unicode Identifier: " + bool1;
String str2 = " Is " + char2 + " a part of Unicode Identifier: " + bool2;
String str3 = " Is " + char3 + " a part of Unicode Identifier: " + bool3;
// Displaying the strings
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
}
}
輸出:
Is - a part of Unicode Identifier: false Is 7 a part of Unicode Identifier: true Is g a part of Unicode Identifier: true
示例2:當傳遞的參數是字符時。
// Code to illustrate the Character.isUnicodeIdentifierPart()
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create 2 char primitives c1, c2
char c1 = '~', c2 = '8';
boolean bool1 = Character.isUnicodeIdentifierPart(c1);
boolean bool2 = Character.isUnicodeIdentifierPart(c2);
String str1 = c1 + " may be part of a Unicode identifier is " + bool1;
String str2 = c2 + " may be part of a Unicode identifier is " + bool2;
System.out.println(str1);
System.out.println(str2);
}
}
輸出:
~ may be part of a Unicode identifier is false 8 may be part of a Unicode identifier is true
以下示例程序旨在說明Character.isUnicodeIdentifierPart(int codePoint)方法:
示例1:
// Code to illustrate the Character.isUnicodeIdentifierPart(int codePoint)
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Create 2 int primitives c1, c2
int c1 = 0x053d, c2 = 0x7840;
boolean bool1 = Character.isUnicodeIdentifierPart(c1);
boolean bool2 = Character.isUnicodeIdentifierPart(c2);
String str1 = "c1 may be part of a Unicode identifier is " + bool1;
String str2 = "c2 may be part of a Unicode identifier is " + bool2;
// Displaying the strings
System.out.println(str1);
System.out.println(str2);
}
}
輸出:
c1 may be part of a Unicode identifier is true c2 may be part of a Unicode identifier is true
示例2:
// Code to illustrate the Character.isUnicodeIdentifierPart(int codePoint)
import java.lang.*;
public class gfg {
public static void main(String[] args)
{
// Creating 2 int primitives c1, c2
int c1 = 0x065d, c2 = 0x7885;
boolean bool1 = Character.isUnicodeIdentifierPart(c1);
boolean bool2 = Character.isUnicodeIdentifierPart(c2);
String str1 = "c1 may be part of a Unicode identifier is " + bool1;
String str2 = "c2 may be part of a Unicode identifier is " + bool2;
// Displaying the strings
System.out.println(str1);
System.out.println(str2);
}
}
輸出:
c1 may be part of a Unicode identifier is true c2 may be part of a Unicode identifier is true
參考: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isUnicodeIdentifierPart(char)
相關用法
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
- Java Clock withZone()用法及代碼示例
- Java Clock tickMinutes()用法及代碼示例
- Java Map get()用法及代碼示例
- Java Set contains()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 Character.isUnicodeIdentifierPart() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。