📜  Java中的字符.isUnicodeIdentifierPart() 方法及示例

📅  最后修改于: 2022-05-13 01:55:06.986000             🧑  作者: Mango

Java中的字符.isUnicodeIdentifierPart() 方法及示例

Java.lang。 字符.isUnicodeIdentifierPart()是Java中的一个内置方法,用于确定指定字符是否可能是 Unicode 标识符的一部分,而不是第一个字符。

当且仅当以下语句之一为真时,字符才可能是 Unicode 标识符的一部分:

  • 它是一个连接标点符号(例如'_')
  • 这是一个数字
  • 这是一封信
  • 它是一个组合标记
  • isIdentifierIgnorable 为该字符返回 true。
  • 它是一个数字字母(例如罗马数字字符)
  • 它是一个非间距标记

句法:

public static boolean isUnicodeIdentifierPart(datatype character)

参数:该函数接受一个强制参数字符。此参数的数据类型可以是 int 或 char。它指定要测试的字符。

返回值:如果字符可能是 Unicode 标识符的一部分,则此方法返回 true,否则返回 false。

下面的程序说明了Java.lang。字符.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

下面的程序说明了字符.isUnicodeIdentifierPart(int codePoint) 方法:

方案一:

// 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

方案二:

// 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: Java/lang/ 字符.html#isUnicodeIdentifierPart(char)