Java Character.UnicodeBlock of(char c) 方法



描述

Java 的 Character.UnicodeBlock of(char c) 方法返回表示包含給定字元的 Unicode 區塊的物件,如果字元不是定義的區塊的成員,則返回 null。

宣告

以下是 java.lang.Character.UnicodeBlock.of() 方法的宣告

public static Character.UnicodeBlock of(char c)

引數

c − 這是字元。

返回值

此方法返回表示此字元所屬 Unicode 區塊的 UnicodeBlock 例項,如果字元不屬於任何 Unicode 區塊,則返回 null。

異常

獲取 BASIC_LATIN 的 UnicodeBlock 示例

以下示例顯示了 Java Character.UnicodeBlock of() 方法的使用方法。我們使用 of() 方法來獲取使用 - 和 = 的 BASIC_LATIN 的 UnicodeBlock。

package com.tutorialspoint;

public class CharacterUnicodeBlockDemo {
 
   public static void main(String[] args) {

      /* returns the object representing the Unicode block containing
         the given character */ 
      System.out.println(Character.UnicodeBlock.of('-'));
      System.out.println(Character.UnicodeBlock.of('='));
   }
}  

讓我們編譯並執行以上程式,這將產生以下結果:

BASIC_LATIN
BASIC_LATIN

獲取 CURRENCY_SYMBOLS 的 UnicodeBlock 示例

以下示例顯示了 Java Character.UnicodeBlock of() 方法的使用方法。我們使用 of() 方法來獲取使用 unicode 的 CURRENCY_SYMBOLS 的 UnicodeBlock。

package com.tutorialspoint;

public class CharacterUnicodeBlockDemo {
 
   public static void main(String[] args) {

      /* returns the object representing the Unicode block containing
         the given character */ 
      System.out.println(Character.UnicodeBlock.of('\u20ac'));
   }
}  

讓我們編譯並執行以上程式,這將產生以下結果:

CURRENCY_SYMBOLS

獲取 BASIC_LATIN 的 UnicodeBlock 示例

以下示例顯示了 Java Character.UnicodeBlock of() 方法的使用方法。我們使用 of() 方法來獲取使用字元 Z 的 BASIC_LATIN 的 UnicodeBlock。

package com.tutorialspoint;

public class CharacterUnicodeBlockDemo {
 
   public static void main(String[] args) {

      /* returns the object representing the Unicode block containing
         the given character */ 
      System.out.println(Character.UnicodeBlock.of('Z'));
   }
}  

讓我們編譯並執行以上程式,這將產生以下結果:

BASIC_LATIN
java_lang_character.unicodeblock.htm
廣告