Java Character codePointOf() Method

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

Definition

In Java, Character.codePointOf(name) is the reverse of getName(): you give it a Unicode character name and it returns the matching code point as an int. codePointOf("LATIN SMALL LETTER A") returns 97.

Matching ignores case and removes leading and trailing whitespace, so "latin small letter a" works too. This lets you write readable code such as codePointOf("GRINNING FACE") instead of a bare 0x1F600.

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

Java 9+ only.

Character.codePointOf(String name) was added in Java 9, so the examples on this page need Java 9 or newer. Java 8 has no built-in reverse lookup; a common workaround is to build your own map once by looping over all code points and calling Character.getName (Java 7+).

Syntax

Pass the character name as a String.

Java
int a = Character.codePointOf("LATIN SMALL LETTER A");    // 97
int b = Character.codePointOf("grinning face");           // 128512 (0x1F600), case ignored
Character.codePointOf("NO SUCH NAME");                     // throws IllegalArgumentException
CallWhat it does
Character.codePointOf(name)Name to code point.
Character.toChars(Character.codePointOf(name))Name to char[], ready for a String.
Character.getName(Character.codePointOf(name))Normalise a name to its official uppercase form.

One overload, codePointOf(String name), added in Java 9.

Library declarations
Java
// java.lang.Character (since Java 9)
public static int codePointOf(String name)

Parameters

ParameterDescription
name (String)A Unicode character name; case and surrounding whitespace are ignored.

Return Value

Return ValueDescription
intThe code point with that name.

Compare with Similar Methods

Related methods:

MethodHow it differs
getName(cp)The reverse: code point to name (Java 7+).
toChars(cp)Turns the result into chars.
isValidCodePoint(cp)Checks a number you already have.

Java Examples

Example 1 — Find Code Points from Their Names

Look up four names and print the code points in decimal and hex.

Java
public class CharacterCodePointOfLookup {
    public static void main(String[] args) {
        String[] names = {"LATIN SMALL LETTER A", "DIGIT ZERO", "SPACE", "GRINNING FACE"};
        for (String n : names) {
            int cp = Character.codePointOf(n);
            System.out.println(n + " -> " + cp + " (0x" + Integer.toHexString(cp) + ")");
        }
    }
}

How It Works

  1. Readable constants. Each name is turned into its number, so code can say what it means instead of using magic numbers.
  2. ASCII and beyond. The first three are ASCII; GRINNING FACE is U+1F600, outside the BMP.
  3. Hex for comparison. Integer.toHexString shows the familiar U+ form of each result.

Example 2 — Names Are Matched Ignoring Case and Outer Spaces

Look up names written in lowercase, mixed case, and with extra spaces, then normalise them with getName.

Java
public class CharacterCodePointOfCase {
    public static void main(String[] args) {
        String[] inputs = {"latin capital letter a", "  Dollar Sign  ", "Thumbs Up Sign"};
        for (String in : inputs) {
            int cp = Character.codePointOf(in);
            System.out.println("[" + in + "] -> " + cp + " -> " + Character.getName(cp));
        }
    }
}

How It Works

  1. Case does not matter. "latin capital letter a" finds 65, the same as the uppercase name.
  2. Outer spaces are trimmed. The brackets show the extra spaces around Dollar Sign; the lookup still finds 36.
  3. Back to the official form. getName returns the canonical uppercase name, a simple way to normalise user input.

Example 3 — Handle Unknown Names and null

Build a String from a name, then pass a name that does not exist and a null.

Java
public class CharacterCodePointOfErrors {
    public static void main(String[] args) {
        String smile = new String(Character.toChars(Character.codePointOf("GRINNING FACE")));
        System.out.println("built from name, length " + smile.length());
        try {
            Character.codePointOf("HAPPY FACE WITH HAT");
        } catch (IllegalArgumentException e) {
            System.out.println("unknown name: IllegalArgumentException");
        }
        try {
            Character.codePointOf(null);
        } catch (NullPointerException e) {
            System.out.println("null: NullPointerException");
        }
    }
}

How It Works

  1. Name to text. toChars turns the code point into a surrogate pair, and new String wraps it: length 2.
  2. No guessing. There is no character called HAPPY FACE WITH HAT, so the method throws instead of returning a near match.
  3. null is rejected. Passing null throws NullPointerException; validate user input before the lookup.

Frequently Asked Questions

Java 9. It does not exist in Java 8.
No. Matching ignores case and removes leading and trailing whitespace.
It throws IllegalArgumentException.
Build a map from Character.getName(cp) to cp by looping over all code points once (getName exists since Java 7), then look names up in the map.
new String(Character.toChars(Character.codePointOf(name))), or on Java 11+ the static toString(int) overload.

Next: compare()

Compare two primitive char values numerically (Java 7+).

compare() 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