Character.charCount() in Java

Character.charCount(): This method is available in java.lang.Character class of Java.

Syntax:

int java.lang.Character.charCount(int codePoint)

This method takes one argument of type int as its parameter. This method determines the number of char values needed to represent the specified character (Unicode code point).

Note: If the specified character is equal to or greater than 0x10000, then the method returns 2. Otherwise, the method returns 1.

Parameters: One parameter is required for this method.

codePoint: the character (Unicode code point) to be tested.

Returns: 2 if the character is a valid supplementary character; 1 otherwise.

Approach

Java

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

        int codePoint = 2;
        System.out.println(Character.charCount(codePoint));
    }
}

Output:

1

No comments:

Post a Comment