Character.getType() in Java

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

Approach 1: When the argument of type char.

Syntax:

int java.lang.Character.getType(char ch)

This method takes one argument of type char as its parameter. This method returns a value indicating a character's general category.

Parameters: ch the character to be tested.

Returns: a value of type int representing the character's general category.

Exceptions: NA( This method does not throw any exceptions).

Java

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

        char ch = 'a';
        System.out.println(Character.getType(ch));
    }
}

Output:

2


Approach 2: When the argument of type int.

Syntax:

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

This method takes one argument of type int as its parameter. This method returns a value indicating a character's general category.

Parameters: One parameter is required for this method.

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

Returns: a value of type int representing the character's general category.

Exceptions: NA (This method does not throw any exceptions).

Java

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

        int codePoint = '@';
        System.out.println(Character.getType(codePoint));
    }
}

Output:

24

No comments:

Post a Comment