Java Character.UnicodeBlock forName() Method



Description

The Java Character.UnicodeBlock forName() method returns the UnicodeBlock with the given name. Block names are determined by The Unicode Standard.This method accepts block names in the following forms −

  • Canonical block names as defined by the Unicode Standard. For example, the standard defines a "Basic Latin" block.

  • Canonical block names with all spaces removed. For example, "BasicLatin" is a valid block name for the "Basic Latin" block.

  • The text representation of each constant UnicodeBlock identifier. For example, this method will return the BASIC_LATIN block if provided with the "BASIC_LATIN" name.

Declaration

Following is the declaration for java.lang.Character.UnicodeBlock.forName() method

public static final Character.UnicodeBlock forName(String blockName)

Parameters

blockName − This is a UnicodeBlock name.

Return Value

This method returns the UnicodeBlock instance identified by blockName.

Exception

  • IllegalArgumentException − if blockName is an invalid name.

  • NullPointerException − if blockName is null.

Getting UnicodeBlock of BASIC_LATIN Example

The following example shows the usage of Java Character.UnicodeBlock forName() method. We're using forName() method to get UnicodeBlock of BASIC_LATIN.

package com.tutorialspoint;

public class CharacterUnicodeBlockDemo {
  
   public static void main(String[] args) {
    
      // returns the UnicodeBlock instance with blockName "BASIC_LATIN"
      System.out.println(Character.UnicodeBlock.forName("BASIC_LATIN"));
  
      // returns the UnicodeBlock instance with blockName "BasicLatin"
      System.out.println(Character.UnicodeBlock.forName("BasicLatin"));
   }
}

Let us compile and run the above program, this will produce the following result −

BASIC_LATIN
BASIC_LATIN

Getting UnicodeBlock of ARABIC Example

The following example shows the usage of Java Character.UnicodeBlock forName() method. We're using forName() method to get UnicodeBlock of ARABIC.

package com.tutorialspoint;

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

      // returns the UnicodeBlock instance with specified blockName 
      System.out.println(Character.UnicodeBlock.forName("ARABIC"));
   }
}

Let us compile and run the above program, this will produce the following result −

ARABIC

Getting UnicodeBlock of MUSICALSYMBOLS and TAMIL Example

The following example shows the usage of Java Character.UnicodeBlock forName() method. We're using forName() method to get UnicodeBlock of MUSICALSYMBOLS and TAMIL.

package com.tutorialspoint;

public class CharacterUnicodeBlockDemo {
  
   public static void main(String[] args) {
      System.out.println(Character.UnicodeBlock.forName("MUSICALSYMBOLS"));
      System.out.println(Character.UnicodeBlock.forName("TAMIL"));
   }
}

Let us compile and run the above program, this will produce the following result −

MUSICAL_SYMBOLS
TAMIL
java_lang_character.unicodeblock.htm
Advertisements