Java Character isSpaceChar() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Character

Definition

In Java, Character.isSpaceChar(ch) returns true when the character's general category is SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR. It is the pure Unicode idea of a space.

So it accepts the ordinary space, the non-breaking space U+00A0, the em space U+2003, the ideographic space U+3000, and U+2028/U+2029, but it rejects tab, newline, and carriage return, because Unicode files those as control characters. That is the opposite trade-off to isWhitespace().

A static method of java.lang.Character (Java 1.1+): call it on the class, as in Character.isSpaceChar(...); you do not need a Character object. No import is needed, because java.lang is always available. The int codePoint overload was added in Java 5.

Unicode version.

The answer comes from the Unicode Character Database built into your JDK, and each Java release follows a specific Unicode version (Java 8, for example, uses Unicode 6.2). The characters used on this page have had the same properties for many Unicode versions, so the examples print the same result on any current JDK.

Syntax

Pass a char or an int code point.

Java
Character.isSpaceChar(' ');        // true
Character.isSpaceChar('\u00A0');   // true, non-breaking space
Character.isSpaceChar('\t');       // false, tab is a control character
Character.isSpaceChar('\n');       // false
CallWhat it does
Character.isSpaceChar(c)Is this a Unicode space or separator?
Character.isSpaceChar(c) && !Character.isWhitespace(c)Find the non-breaking spaces.
Character.isSpaceChar(c) || Character.isWhitespace(c)Treat every kind of space and line break alike.

Overloads: isSpaceChar(char ch) and isSpaceChar(int codePoint). The older Character.isSpace(char) is deprecated; use this method or isWhitespace instead.

Library declarations
Java
// java.lang.Character
public static boolean isSpaceChar(char ch)
public static boolean isSpaceChar(int codePoint)   // since Java 5

Parameters

ParameterDescription
ch (char)The character to test.
codePoint (int)The Unicode code point to test.

Return Value

Return ValueDescription
trueThe category is SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR.
falseAnything else, including tab, newline, and the zero width space U+200B (a format character).

Compare with Similar Methods

How it differs from the other tests:

MethodHow it differs
isWhitespace(ch)Includes tab, newline, and carriage return; excludes U+00A0, U+2007, and U+202F.
getType(ch)Returns the category itself, such as SPACE_SEPARATOR (12).
isISOControl(ch)Where tab and newline belong instead.

Java Examples

Example 1 — Seven Characters, Two Definitions of Space

Compare both tests on the usual suspects.

Java
public class CharacterIsSpaceCharTable {
    public static void main(String[] args) {
        char[] chars = {' ', '\t', '\n', '\u00A0', '\u2003', '\u2028', 'a'};
        for (char c : chars) {
            System.out.println((int) c + " spaceChar=" + Character.isSpaceChar(c)
                    + " whitespace=" + Character.isWhitespace(c));
        }
    }
}

How It Works

  1. Both agree on the space. U+0020 (32), the em space (8195), and LINE SEPARATOR U+2028 (8232) pass both tests.
  2. Controls split them. Tab and newline are control characters, so only isWhitespace accepts them.
  3. The non-breaking space goes the other way. U+00A0 (160) is a Unicode space separator, so only isSpaceChar accepts it.

Example 2 — Mark Every Kind of Space in a String

Replace Unicode spaces with _ and the remaining whitespace (here a tab) with ~.

Java
public class CharacterIsSpaceCharMark {
    public static void main(String[] args) {
        String text = "a\u00A0b\u2003c\td e";
        StringBuilder shown = new StringBuilder();
        for (char c : text.toCharArray()) {
            if (Character.isSpaceChar(c)) {
                shown.append('_');
            } else if (Character.isWhitespace(c)) {
                shown.append('~');
            } else {
                shown.append(c);
            }
        }
        System.out.println(shown);
    }
}

How It Works

  1. Three Unicode spaces. The non-breaking space, the em space, and the normal space before e are all SPACE_SEPARATOR, so each turns into _.
  2. The tab falls through. '\t' fails isSpaceChar but passes isWhitespace in the else if, so it becomes ~.
  3. Readable debugging. The output is plain ASCII, so you can see exactly where the invisible characters were.

Example 3 — isSpaceChar and the Three Separator Categories

Print the category name of four characters next to the isSpaceChar result.

Java
public class CharacterIsSpaceCharCategory {
    static String category(int type) {
        if (type == Character.SPACE_SEPARATOR) return "SPACE_SEPARATOR";
        if (type == Character.LINE_SEPARATOR) return "LINE_SEPARATOR";
        if (type == Character.PARAGRAPH_SEPARATOR) return "PARAGRAPH_SEPARATOR";
        if (type == Character.FORMAT) return "FORMAT";
        return "other (" + type + ")";
    }

    public static void main(String[] args) {
        char[] chars = {' ', '\u3000', '\u2029', '\u200B'};
        for (char c : chars) {
            System.out.println((int) c + " " + category(Character.getType(c))
                    + " spaceChar=" + Character.isSpaceChar(c));
        }
    }
}

How It Works

  1. Constants, not magic numbers. The helper compares getType with Character.SPACE_SEPARATOR and friends, which reads better than 12, 13, and 14.
  2. Wide and paragraph spaces. The ideographic space U+3000 (12288) used in CJK text is a space separator, and U+2029 (8233) is the paragraph separator; both pass.
  3. Zero width is not a space. U+200B ZERO WIDTH SPACE has the category FORMAT despite its name, so isSpaceChar returns false.

Frequently Asked Questions

No. Tab, newline, and carriage return are control characters in Unicode, so isSpaceChar returns false. isWhitespace returns true for them.
Character.isSpaceChar(c) && !Character.isWhitespace(c) is true for U+00A0, U+2007, and U+202F. Or compare with '\u00A0' directly.
That getType returns SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR.
No. Its category is FORMAT, so isSpaceChar is false. isIdentifierIgnorable returns true for it.
isWhitespace for Java-style whitespace and isSpaceChar for Unicode spaces. isSpace only recognised five ASCII characters.

Next: isSupplementaryCodePoint()

Check whether a code point is above U+FFFF and needs a surrogate pair.

isSupplementaryCodePoint() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful