0Pricing
Java Academy · Lesson

Character Helper Methods

isDigit, isLetter, toUpperCase.

The Character Class

Java's Character class provides handy static helper methods for working with chars.

You call them on the class itself, passing a char as the argument, like Character.isDigit(c). They return useful answers without you doing math by hand.

char c = '4';
boolean digit = Character.isDigit(c);

Checking for Digits

Character.isDigit(c) returns true when the char is a number from '0' to '9'.

This is cleaner and safer than comparing codes yourself, and it also understands digits from other languages.

public class Main {
    public static void main(String[] args) {
        System.out.println(Character.isDigit('8'));
        System.out.println(Character.isDigit('x'));
    }
}

All lessons in this course

  1. The char Primitive
  2. Character Helper Methods
  3. Looping Over Characters
  4. Counting and Filtering Chars
← Back to Java Academy