KnowledgeBoat Logo
|

Computer Applications

How can you check if a given character is a digit, a letter or a space?

Java Library Classes

3 Likes

Answer

We can check if a given character is a digit, a letter or a space by using the following methods of Character class:

  1. isDigit(char) — It returns true if the specified character is a digit; returns false otherwise.
    Syntax:
    boolean isDigit(char ch)

  2. isLetter(char) — It returns true if the specified character is a letter; returns false otherwise.
    Syntax:
    boolean isLetter(char ch)

  3. isLetterOrDigit(char) — It returns true if the specified character is a letter or a digit; returns false otherwise.
    Syntax:
    boolean isLetterOrDigit(char ch)

  4. isWhitespace(char) — It returns true if the specified character is whitespace; returns false otherwise.
    Syntax:
    boolean isWhitespace(char ch)

Answered By

3 Likes


Related Questions