Java Character Class

java

In Java, the java.lang.Character class is a wrapper class that represents a single Unicode character. It provides methods for working with characters, such as checking the character’s type, converting the character to a string, and comparing characters.

Here are some common methods of the Character class:

char charValue(): Returns the primitive char value represented by this Character object.
boolean isLetter(): Determines whether the specified character is a letter.
boolean isDigit(): Determines whether the specified character is a digit.
boolean isWhitespace(): Determines whether the specified character is a whitespace character.
boolean isUpperCase(): Determines whether the specified character is an uppercase character.
boolean isLowerCase(): Determines whether the specified character is a lowercase character.
char toUpperCase(char ch): Converts the specified character to uppercase.
char toLowerCase(char ch): Converts the specified character to lowercase.

Here is an example of how to use the Character class:

char c = 'A';
Character ch = c; // ch is a Character object with the value 'A'

boolean b1 = ch.isLetter(); // b1 is true
boolean b2 = ch.isDigit(); // b2 is false
boolean b3 = ch.isWhitespace(); // b3 is false
boolean b4 = ch.isUpperCase(); // b4 is true
boolean b5 = ch.isLowerCase(); // b5 is false

char c2 = ch.toLowerCase(c); // c2 is 'a'