Java Character toCodePoint() Method

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

Definition

In Java, Character.toCodePoint(high, low) converts a surrogate pair into the supplementary code point it stands for. toCodePoint('\uD83D', '\uDE00') returns 128512, which is U+1F600.

The math is the reverse of encoding: take 10 bits from each surrogate, join them into a 20-bit number, and add 0x10000. That is what codePointAt() does internally when it finds a pair.

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

Syntax

Pass the high surrogate first and the low surrogate second.

Java
int a = Character.toCodePoint('\uD83D', '\uDE00');   // 128512 (0x1F600)
int b = Character.toCodePoint('\uD800', '\uDC00');   // 65536 (0x10000)
int c = Character.toCodePoint('\uDBFF', '\uDFFF');   // 1114111 (0x10FFFF)
CallWhat it does
Character.toCodePoint(s.charAt(i), s.charAt(i + 1))Decode a pair found at index i.
Character.isSurrogatePair(h, l) ? Character.toCodePoint(h, l) : -1Decode only valid pairs.
((h - 0xD800) << 10) + (l - 0xDC00) + 0x10000The same formula by hand.

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

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

Parameters

ParameterDescription
high (char)The high surrogate, 0xD800 to 0xDBFF.
low (char)The low surrogate, 0xDC00 to 0xDFFF.

Return Value

Return ValueDescription
intThe supplementary code point, 0x10000 to 0x10FFFF, for a valid pair.

Compare with Similar Methods

Other ways to get a code point:

MethodHow it differs
codePointAt(seq, i)Finds, checks, and decodes a pair in one step.
isSurrogatePair(h, l)The check to run before toCodePoint.
toChars(cp)The reverse: code point to chars.

Java Examples

Example 1 — Decode Three Surrogate Pairs

Combine the pairs for the first, an emoji, and the last supplementary code point.

Java
public class CharacterToCodePointValues {
    public static void main(String[] args) {
        char[][] pairs = { {'\uD800', '\uDC00'}, {'\uD83D', '\uDE00'}, {'\uDBFF', '\uDFFF'} };
        for (char[] p : pairs) {
            int cp = Character.toCodePoint(p[0], p[1]);
            System.out.println(cp + " = 0x" + Integer.toHexString(cp));
        }
    }
}

How It Works

  1. An array of pairs. Each inner char[] holds a high surrogate at index 0 and a low surrogate at index 1.
  2. The smallest and largest. 0xD800 with 0xDC00 gives 0x10000, and 0xDBFF with 0xDFFF gives 0x10FFFF.
  3. The emoji in the middle. 0xD83D with 0xDE00 gives 0x1F600, the same value codePointAt returns for that string.

Example 2 — toCodePoint vs the Decoding Formula

Decode the THUMBS UP and G CLEF pairs both ways and print the steps for one of them.

Java
public class CharacterToCodePointFormula {
    public static void main(String[] args) {
        char[][] pairs = { {'\uD83D', '\uDC4D'}, {'\uD834', '\uDD1E'} };
        for (char[] p : pairs) {
            int byMethod = Character.toCodePoint(p[0], p[1]);
            int byHand = ((p[0] - 0xD800) << 10) + (p[1] - 0xDC00) + 0x10000;
            System.out.println("0x" + Integer.toHexString(byMethod) + " same=" + (byMethod == byHand));
        }
        char h = '\uD83D', l = '\uDC4D';
        System.out.println("high bits 0x" + Integer.toHexString(h - 0xD800)
                + ", low bits 0x" + Integer.toHexString(l - 0xDC00));
    }
}

How It Works

  1. Remove the offsets. Subtracting 0xD800 and 0xDC00 leaves two 10-bit numbers: 0x3D and 0x4D for THUMBS UP.
  2. Join and shift. 0x3D << 10 is 0xF400; adding 0x4D gives 0xF44D, and adding 0x10000 gives 0x1F44D.
  3. Same as the library. Both pairs decode identically by hand and with toCodePoint, including MUSICAL SYMBOL G CLEF (0x1D11E).

Example 3 — Decode Safely: isSurrogatePair Before toCodePoint

Wrap toCodePoint in a helper that returns -1 for anything that is not a valid pair.

Java
public class CharacterToCodePointSafe {
    static int decode(char high, char low) {
        return Character.isSurrogatePair(high, low) ? Character.toCodePoint(high, low) : -1;
    }

    public static void main(String[] args) {
        System.out.println("valid pair:    " + decode('\uD83D', '\uDE00'));
        System.out.println("swapped pair:  " + decode('\uDE00', '\uD83D'));
        System.out.println("two letters:   " + decode('a', 'b'));
    }
}

How It Works

  1. Check, then convert. The conditional expression only calls toCodePoint when isSurrogatePair has confirmed the order and ranges.
  2. A clear failure value. No code point is negative, so -1 cannot be confused with a real result.
  3. Why it matters. Without the check, the swapped pair and the two letters would still produce some number, because toCodePoint itself never complains.

Frequently Asked Questions

It converts a high surrogate and a low surrogate into the supplementary code point they encode, from 0x10000 to 0x10FFFF.
No. It assumes a valid pair. Call isSurrogatePair(high, low) first if you are not sure.
The high surrogate (0xD800 to 0xDBFF), then the low surrogate (0xDC00 to 0xDFFF), the same order as in a String.
((high - 0xD800) << 10) + (low - 0xDC00) + 0x10000.
When the chars are inside a String or array: codePointAt finds the pair, checks it, and decodes it in one call.

Next: toLowerCase()

Convert one character to lowercase, using Unicode rules.

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

8 people found this page helpful