Java Character isSurrogatePair() Method

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

Definition

In Java, Character.isSurrogatePair(high, low) returns true when high is a high surrogate and low is a low surrogate. Only then do the two chars encode one supplementary character, which toCodePoint() can decode.

The order matters: a low surrogate followed by a high surrogate is not a pair. Two high surrogates in a row, or a surrogate next to an ordinary char, are not pairs either.

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

Syntax

Pass the two chars in the order they appear in the text.

Java
Character.isSurrogatePair('\uD83D', '\uDE00');   // true, U+1F600
Character.isSurrogatePair('\uDE00', '\uD83D');   // false, wrong order
Character.isSurrogatePair('\uD83D', 'A');        // false
Character.isSurrogatePair('a', 'b');             // false
CallWhat it does
Character.isSurrogatePair(s.charAt(i), s.charAt(i + 1))Does a valid pair start at i?
if (Character.isSurrogatePair(h, l)) cp = Character.toCodePoint(h, l);Decode only when it is safe.
Character.isHighSurrogate(h) && Character.isLowSurrogate(l)What the method checks.

One overload, isSurrogatePair(char high, char low), since Java 5.

Library declarations
Java
// java.lang.Character (since Java 5)
public static boolean isSurrogatePair(char high, char low)

Parameters

ParameterDescription
high (char)The first char; must be a high surrogate for a true result.
low (char)The second char; must be a low surrogate.

Return Value

Return ValueDescription
trueisHighSurrogate(high) && isLowSurrogate(low).
falseAny other combination.

Compare with Similar Methods

Related surrogate checks:

MethodHow it differs
isHighSurrogate(ch)Checks the first char alone.
toCodePoint(high, low)Decodes a pair without checking it.
codePointAt(seq, i)Checks and decodes in one call.

Java Examples

Example 1 — Valid Pairs, Reversed Pairs, and Non-Pairs

Try the emoji's two halves in both orders, a doubled high surrogate, and two letters.

Java
public class CharacterIsSurrogatePairTable {
    public static void main(String[] args) {
        char hi = '\uD83D';
        char lo = '\uDE00';
        System.out.println("(hi, lo) -> " + Character.isSurrogatePair(hi, lo));
        System.out.println("(lo, hi) -> " + Character.isSurrogatePair(lo, hi));
        System.out.println("(hi, hi) -> " + Character.isSurrogatePair(hi, hi));
        System.out.println("(a, b)   -> " + Character.isSurrogatePair('a', 'b'));
    }
}

How It Works

  1. The correct order. High surrogate first, low surrogate second: this is how U+1F600 appears in a String.
  2. Reversed is invalid. The same two chars in the other order fail, because the first argument must be a high surrogate.
  3. Not even surrogates. Two high surrogates, or two letters, can never form a pair.

Example 2 — Check That Every Surrogate in a String Is Paired

A string is well-formed UTF-16 when every surrogate is part of a valid pair. Check three strings.

Java
public class CharacterIsSurrogatePairWellFormed {
    static boolean wellFormed(String s) {
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isSurrogate(c)) {
                if (i + 1 < s.length() && Character.isSurrogatePair(c, s.charAt(i + 1))) {
                    i++;
                } else {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println("ok + emoji:   " + wellFormed("ok\uD83D\uDE00"));
        System.out.println("cut emoji:    " + wellFormed("bad\uD83D"));
        System.out.println("stray low:    " + wellFormed("\uDE00bad"));
    }
}

How It Works

  1. Only surrogates need checking. Ordinary chars are always fine; the loop only stops to look at chars that pass isSurrogate.
  2. Pair, then skip. A valid pair advances i past the low half; anything else ends the check with false.
  3. Two kinds of damage. A high surrogate at the very end and a low surrogate at the very start both make the string malformed.

Example 3 — Decode a char Array, Keeping Invalid Halves As They Are

Join valid pairs with toCodePoint; leave anything else as a single char value.

Java
public class CharacterIsSurrogatePairDecode {
    public static void main(String[] args) {
        char[] data = {'\uD834', '\uDD1E', '\uDD1E', '\uD834'};
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < data.length; i++) {
            if (i + 1 < data.length && Character.isSurrogatePair(data[i], data[i + 1])) {
                out.append(Character.toCodePoint(data[i], data[i + 1])).append(' ');
                i++;
            } else {
                out.append((int) data[i]).append(' ');
            }
        }
        System.out.println(out.toString().trim());
    }
}

How It Works

  1. A real pair first. 0xD834 followed by 0xDD1E is MUSICAL SYMBOL G CLEF, which decodes to 119070 (0x1D11E).
  2. The reverse order. The next two chars are 0xDD1E then 0xD834: low before high, so isSurrogatePair is false.
  3. Kept as single values. The two leftover halves are printed as 56606 and 55348, the way codePointAt reports unpaired surrogates.

Frequently Asked Questions

That the first char is a high surrogate (0xD800 to 0xDBFF) and the second is a low surrogate (0xDC00 to 0xDFFF).
Yes. isSurrogatePair(low, high) is false. In UTF-16 the high surrogate always comes first.
toCodePoint does not validate its arguments, so an invalid pair gives a meaningless result instead of an error.
Walk the chars and make sure every surrogate is part of an isSurrogatePair match. Java 8 has no built-in method for this.
No. Surrogate pairs only exist at the char level. Once decoded, a code point is checked with isSupplementaryCodePoint.

Next: isTitleCase()

Check for titlecase letters, the "capitalised" form of digraphs such as Dz.

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

15 people found this page helpful