Character.UnicodeBlock.of(): This method is available in java.lang.Character.UnicodeBlock.
Syntax:
UnicodeBlock java.lang.Character.UnicodeBlock.of(int codePoint)
This method takes one argument of type int as its parameter. This method returns the object representing the Unicode block containing the given character (Unicode code point), or null if the character is not a member of a defined block.
Parameters: One parameter is required for this method.
codePoint: the character (Unicode code point) in question.
Returns: The UnicodeBlock instance representing the Unicode block of which this character is a member, or null if the character is not a member of any Unicode block.
Throws:
IllegalArgumentException - if the specified codePoint is an invalid Unicode code point.
Approach 1: When no exceptions.
Java
public class CharacterUnicodeBlockintof {public static void main(String[] args) {int codePoint = 'a';System.out.println(Character.UnicodeBlock.of(codePoint));}}
Output:
BASIC_LATIN
Approach 2: IllegalArgumentException
Java
public class CharacterUnicodeBlockintof {public static void main(String[] args) {int codePoint = -1;System.out.println(Character.UnicodeBlock.of(codePoint));}}
Output:
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid Unicode code point: 0xFFFFFFFF at java.base/java.lang.Character$UnicodeBlock.of(Character.java:4153)
No comments:
Post a Comment