Java.lang.Character.getType() Method
Advertisements
Description
The java.lang.Character.getType(char ch) returns a value indicating a character's general category.
Declaration
Following is the declaration for java.lang.Character.getType() method
public static int getType(char ch)
Parameters
ch - the character to be tested
Return Value
This method returns a value of type int representing the character's general category.
Exception
NA
Example
The following example shows the usage of lang.Character.getType() method.
package com.tutorialspoint;
import java.lang.*;
public class CharacterDemo {
public static void main(String[] args) {
// create 2 character primitives ch1, ch2
char ch1, ch2;
// assign values to ch1, ch2
ch1 = 'M';
ch2 = '$';
// create 2 int primitives i1, i2
int i1, i2;
// assign getType values of ch1, ch2 to i1, i2
i1 = Character.getType(ch1);
i2 = Character.getType(ch2);
/**
* value 1 represents UPPERCASE_LETTER
* value 26 represents CURRENCY_SYMBOL
*/
String str1 = "Category of " + ch1 + " is " + i1;
String str2 = "Category of " + ch2 + " is " + i2;
// print i1, i2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
Let us compile and run the above program, this will produce the following result:
Category of M is 1 Category of $ is 26