5.3 The Character Class
char is a primitive data type and has no methods. For this reason, the Character class in the java.lang core package includes a large number of methods that are useful for dealing with single characters; many of these methods are static. This class includes methods for testing, such as whether a character is a digit, a letter, or a special character.
5.3.1 Is That So?
What all test methods have in common is that they start with the prefix is and return a boolean . In addition, methods are available for converting, for example, to uppercase or lowercase. The following list includes a few examples:
|
Expression |
Result |
|---|---|
|
Character.isDigit( '0' ) |
true |
|
Character.isDigit( '-' ) |
false |
|
Character.isLetter( ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access