Java Character isSurrogate() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 7+

Definition

In Java, Character.isSurrogate(ch) returns true when the char is a surrogate of either kind: high (0xD800 to 0xDBFF) or low (0xDC00 to 0xDFFF). The whole range is 0xD800 to 0xDFFF.

It answers a simple question: "is this char part of a character above U+FFFF?" If no char in a string is a surrogate, every char is a whole character, and char-by-char code is safe.

A static method of java.lang.Character (Java 7+): call it on the class, as in Character.isSurrogate(...); you do not need a Character object. No import is needed, because java.lang is always available.

Syntax

Pass one char.

Java
Character.isSurrogate('\uD83D');   // true, high
Character.isSurrogate('\uDE00');   // true, low
Character.isSurrogate('A');        // false
Character.isSurrogate('\uE000');   // false
CallWhat it does
Character.isSurrogate(c)Is this char half of a pair?
Character.isHighSurrogate(c) || Character.isLowSurrogate(c)Equivalent check that also works on Java 5 and 6.
c >= Character.MIN_SURROGATE && c <= Character.MAX_SURROGATEThe range check written out.

One overload, isSurrogate(char ch), added in Java 7. The range constants Character.MIN_SURROGATE and Character.MAX_SURROGATE exist since Java 5.

Library declarations
Java
// java.lang.Character (since Java 7)
public static boolean isSurrogate(char ch)

public static final char MIN_SURROGATE = '\uD800';
public static final char MAX_SURROGATE = '\uDFFF';

Parameters

ParameterDescription
ch (char)The char to test.

Return Value

Return ValueDescription
truech is from 0xD800 to 0xDFFF.
falseAny other char.

Compare with Similar Methods

Narrower and wider checks:

MethodHow it differs
isHighSurrogate(ch)Only 0xD800 to 0xDBFF.
isLowSurrogate(ch)Only 0xDC00 to 0xDFFF.
getType(ch)Surrogates report the category SURROGATE (19).

Java Examples

Example 1 — Where the Surrogate Range Starts and Ends

Test the chars just outside, at, and inside both ends of the range.

Java
public class CharacterIsSurrogateTable {
    public static void main(String[] args) {
        char[] chars = {'\uD7FF', '\uD800', '\uDBFF', '\uDC00', '\uDFFF', '\uE000'};
        for (char c : chars) {
            System.out.println("0x" + Integer.toHexString(c) + " surrogate=" + Character.isSurrogate(c));
        }
    }
}

How It Works

  1. Both halves count. 0xD800 and 0xDBFF are high surrogates, 0xDC00 and 0xDFFF are low ones; all four return true.
  2. One step outside. 0xD7FF is just below the range and 0xE000 starts the private use area, so both are false.
  3. 2048 surrogates. The range 0xD800 to 0xDFFF holds 2048 values: 1024 high and 1024 low.

Example 2 — Check Whether a String Has Any Surrogates

If a string contains no surrogate chars, every char is a whole character and simple charAt loops are correct.

Java
public class CharacterIsSurrogateBmpOnly {
    static int surrogates(String s) {
        int n = 0;
        for (int i = 0; i < s.length(); i++) {
            if (Character.isSurrogate(s.charAt(i))) n++;
        }
        return n;
    }

    public static void main(String[] args) {
        String[] texts = {"plain text", "caf\u00E9", "smile \uD83D\uDE00"};
        for (String t : texts) {
            int n = surrogates(t);
            System.out.println("length " + t.length() + ": " + n + " surrogate chars"
                    + (n == 0 ? ", char loops are safe" : ""));
        }
    }
}

How It Works

  1. Accents are fine. "caf\u00E9" contains a non-ASCII letter, but U+00E9 is in the BMP, so it has no surrogates.
  2. An emoji adds two. "smile " is 6 chars and the emoji adds a high and a low surrogate, giving length 8 and 2 surrogate chars.
  3. A quick safety check. Counting surrogates once tells you whether you need code point methods for the rest of the processing.

Example 3 — isSurrogate vs Its Pre-Java-7 Equivalents

Print the range constants and confirm that the two older checks agree with isSurrogate across the whole char range.

Java
public class CharacterIsSurrogateEquivalent {
    public static void main(String[] args) {
        System.out.println("MIN_SURROGATE=0x" + Integer.toHexString(Character.MIN_SURROGATE)
                + " MAX_SURROGATE=0x" + Integer.toHexString(Character.MAX_SURROGATE));
        int mismatches = 0;
        int count = 0;
        for (int i = 0; i <= 0xFFFF; i++) {
            char c = (char) i;
            boolean viaHalves = Character.isHighSurrogate(c) || Character.isLowSurrogate(c);
            boolean viaRange = c >= Character.MIN_SURROGATE && c <= Character.MAX_SURROGATE;
            if (Character.isSurrogate(c)) count++;
            if (viaHalves != Character.isSurrogate(c) || viaRange != Character.isSurrogate(c)) mismatches++;
        }
        System.out.println("surrogates=" + count + " mismatches=" + mismatches);
    }
}

How It Works

  1. An int loop for all chars. Looping with an int from 0 to 0xFFFF and casting avoids the endless loop a char counter would cause, because a char is never greater than 0xFFFF.
  2. Two old-style checks. "high or low" and "between MIN_SURROGATE and MAX_SURROGATE" both work on Java 5 and 6.
  3. Full agreement. All 65536 chars give the same answer three ways, and exactly 2048 of them are surrogates.

Frequently Asked Questions

Java 7. On older versions use isHighSurrogate(c) || isLowSurrogate(c).
0xD800 to 0xDFFF inclusive, which covers both high and low surrogates.
No. It looks at one char only. Use isSurrogatePair(high, low) to check two chars in order.
Surrogates are a char-level detail of UTF-16. For code points, use isBmpCodePoint or isSupplementaryCodePoint.
2048: 1024 high surrogates and 1024 low surrogates, enough to encode the 1,048,576 supplementary code points.

Next: isSurrogatePair()

Check whether two chars form a valid surrogate pair, in the right order.

isSurrogatePair() 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.

14 people found this page helpful