Java Character isHighSurrogate() Method

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

Definition

In Java, Character.isHighSurrogate(ch) returns true when the char is a high surrogate (also called a leading surrogate): a value from 0xD800 to 0xDBFF. A high surrogate is always meant to be followed by a low surrogate; together they encode one character above U+FFFF.

On its own, a high surrogate is not a character. Seeing one at the end of a string, or not followed by a low surrogate, means the text was cut in the middle of a character or is corrupted.

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

Syntax

Pass one char; there is no int overload.

Java
Character.isHighSurrogate('\uD83D');   // true, first half of U+1F600
Character.isHighSurrogate('\uDE00');   // false, that is a low surrogate
Character.isHighSurrogate('A');        // false
"\uD83D\uDE00".charAt(0)               // '\uD83D', a high surrogate
CallWhat it does
Character.isHighSurrogate(s.charAt(i))Does a two-char character start at i?
Character.isHighSurrogate(s.charAt(s.length() - 1))Was the string cut in the middle of a character?
c >= Character.MIN_HIGH_SURROGATE && c <= Character.MAX_HIGH_SURROGATEThe same range check written out.

One overload, isHighSurrogate(char ch), since Java 5. The range is available as Character.MIN_HIGH_SURROGATE and Character.MAX_HIGH_SURROGATE.

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

public static final char MIN_HIGH_SURROGATE = '\uD800';
public static final char MAX_HIGH_SURROGATE = '\uDBFF';

Parameters

ParameterDescription
ch (char)The char to test.

Return Value

Return ValueDescription
truech is from 0xD800 to 0xDBFF.
falseAny other char, including low surrogates.

Compare with Similar Methods

The surrogate family:

MethodHow it differs
isLowSurrogate(ch)The second half: 0xDC00 to 0xDFFF.
isSurrogate(ch)Either half (Java 7+).
highSurrogate(cp)Computes the high surrogate of a code point (Java 7+).

Java Examples

Example 1 — High Surrogates and Their Neighbours

Test the two ends of the high range, the emoji's first half, a low surrogate, and a letter.

Java
public class CharacterIsHighSurrogateTable {
    public static void main(String[] args) {
        char[] chars = {'A', '\uD800', '\uD83D', '\uDBFF', '\uDC00', '\uDE00'};
        for (char c : chars) {
            System.out.println("0x" + Integer.toHexString(c) + " high=" + Character.isHighSurrogate(c));
        }
    }
}

How It Works

  1. The high range. 0xD800, 0xD83D, and 0xDBFF all lie between MIN_HIGH_SURROGATE and MAX_HIGH_SURROGATE.
  2. Low surrogates are different. 0xDC00 and 0xDE00 belong to the low range that starts right after 0xDBFF, so they return false.
  3. Print in hex. Surrogates are easiest to read in hex, so Integer.toHexString(c) is used instead of a decimal cast.

Example 2 — Detect and Repair Text Cut in the Middle of an Emoji

A message was truncated to 3 chars and lost the second half of an emoji. Check the last char and drop the broken half.

Java
public class CharacterIsHighSurrogateTruncated {
    public static void main(String[] args) {
        String full = "Hi\uD83D\uDE00";
        String cut = full.substring(0, 3);
        char last = cut.charAt(cut.length() - 1);
        if (Character.isHighSurrogate(last)) {
            System.out.println("cut inside a character");
            cut = cut.substring(0, cut.length() - 1);
        }
        System.out.println("repaired: " + cut + " (length " + cut.length() + ")");
    }
}

How It Works

  1. A naive cut. substring(0, 3) keeps H, i, and the high surrogate 0xD83D, but not the low surrogate that completes the emoji.
  2. The last char gives it away. A string should never end with a high surrogate, so isHighSurrogate(last) detects the problem.
  3. Drop the half. Removing the dangling surrogate leaves valid text, Hi, instead of a broken character that may display as a question mark.

Example 3 — Count Pairs and Lone High Surrogates in a char Loop

Walk the chars yourself: a high surrogate followed by a low one is a pair; a high surrogate followed by anything else is broken.

Java
public class CharacterIsHighSurrogateScan {
    public static void main(String[] args) {
        String s = "a\uD83D\uDE00b\uD83Dc";
        int pairs = 0, lone = 0, other = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isHighSurrogate(c)) {
                if (i + 1 < s.length() && Character.isLowSurrogate(s.charAt(i + 1))) {
                    pairs++;
                    i++;
                } else {
                    lone++;
                }
            } else {
                other++;
            }
        }
        System.out.println("pairs=" + pairs + " loneHigh=" + lone + " other=" + other);
    }
}

How It Works

  1. Look one char ahead. When a high surrogate is found, the code checks that a next char exists and is a low surrogate.
  2. Skip the second half. For a real pair, i++ jumps over the low surrogate so it is not counted again.
  3. A broken half. The second 0xD83D is followed by 'c', so it counts as a lone high surrogate; a, b, and c make up other.

Frequently Asked Questions

A char from 0xD800 to 0xDBFF. It is the first of the two chars that UTF-16 uses for a code point above U+FFFF.
No. It only has meaning together with the low surrogate that follows it. A lone high surrogate is malformed text.
Surrogates are a UTF-16 storage detail, so the method works on char values, which is how they appear inside Strings.
Check Character.isHighSurrogate(s.charAt(s.length() - 1)) on a non-empty String.
Constants in Character for the range ends, \uD800 and \uDBFF.

Next: isIdentifierIgnorable()

Check whether a character is ignorable inside a Java or Unicode identifier.

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

10 people found this page helpful