In Java, the Character
class is a wrapper class for the char
primitive type. It provides utility methods for working with char
values, such as converting them to and from strings, testing their type (such as whether they are letters or digits), and converting them to upper- or lowercase.
Here are some examples of using the Character
class:
char
value to a String
, you can use the toString
method:char ch = 'A'; String str = Character.toString(ch); // str is "A"
char
value is a letter, you can use the isLetter
method:char ch = 'A'; boolean isLetter = Character.isLetter(ch); // isLetter is true
char
value is a digit, you can use the isDigit
method:char ch = '3'; boolean isDigit = Character.isDigit(ch); // isDigit is true
char
value to upper- or lowercase, you can use the toUpperCase
or toLowerCase
method:char ch = 'a'; char upperCase = Character.toUpperCase(ch); // upperCase is 'A' char lowerCase = Character.toLowerCase(ch); // lowerCase is 'a'
The Character
class also provides other utility methods for working with char
values, such as isWhitespace
, isUpperCase
, and isLowerCase
. You can find more information about these methods in the Java documentation.