GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — StringBuffer codePointAt() method in Java with Examples - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

StringBuffer codePointAt() method in Java with Examples

Last Updated : 18 Aug, 2026

The codePointAt() method of the StringBuffer class is used to return the Unicode code point of the character at the specified index. If the character at the specified index is a high surrogate and the next character is a low surrogate, the method returns the Unicode code point represented by the surrogate pair.

  • It supports Unicode characters represented using surrogate pairs.
  • It throws IndexOutOfBoundsException if the index is invalid.+
Java
public class GFG {
    public static void main(String[] args) {

        // Create a StringBuffer object
        StringBuffer str = new StringBuffer("Geeksforgeeks");

        // Get Unicode code point at index 10
        int codePoint = str.codePointAt(10);

        // Print the result
        System.out.println(
            "Unicode of Character at Index 10 = " + codePoint);
    }
}

Output
Unicode of Character at Index 10 = 101

Explanation: The character at index 10 is e. Its Unicode code point is 101, so codePointAt(10) returns 101.

Syntax

public int codePointAt(int index)

  • Parameters: index –> the index of the character whose Unicode code point is to be returned.
  • Return Value: Returns the Unicode code point at the specified index.
  • Exception: IndexOutOfBoundsException –> thrown if the index is negative or greater than or equal to length().

Example: To demonstrate IndexOutOfBoundsException

Java
public class GFG {
    public static void main(String[] args) {

        // Create a StringBuffer object
        StringBuffer str =
            new StringBuffer("GeeksForGeeks Contribute");

        try {

            // Index 25 is outside the valid range
            int codePoint = str.codePointAt(25);

            System.out.println("Code Point: " + codePoint);
        }
        catch (IndexOutOfBoundsException e) {

            System.out.println("Exception: " + e);
        }
    }
}

Output
Exception: java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 24

Explanation: The valid indexes range from 0 to length() - 1. Since index 25 is outside the valid range, codePointAt() throws an IndexOutOfBoundsException.

Advantages of codePointAt()

  • Returns the Unicode code point of a character.
  • Supports Unicode characters represented by surrogate pairs.
  • Useful for working with Unicode text.
  • Provides direct access to a character's code point using its index.
  • Throws an exception for invalid indexes, helping identify incorrect access.
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.