Java String codePointAt() Method Last Updated : 09 Jan, 2025 Comments Improve Suggest changes Like Article Like Report The codePointAt() method in Java is part of the String class. It is used to return the Unicode value of the character at the specified index in the string. This method is very useful when working with characters beyond the Basic Multilingual Plane (BMP), such as emojis or special symbols.Example 1: The below Java program demonstrates how to retrieve the Unicode value of a character at the specified index. Java // Java Program to demonstrate // the working of codePointAt() method public class Geeks { public static void main(String[] args) { String s = "Hello"; // Get the Unicode code point of // the character at index 1 int a = s.codePointAt(1); System.out.println( "Unicode value of character at index 1: " + a); } } OutputUnicode value of character at index 1: 101 Syntax of codePointAt() Methodpublic int codePointAt(int index)Parameter: The index of the character to retrieve the Unicode code point. It must be within the range 0 to string length - 1.Return Type: Return an int value representing the Unicode value at the specified index.Example 2: The below Java program demonstrates how to retrieve the Unicode value of a character including an emoji, at a specified index in a string. Java // Java program to demonstrate how to // retrieve the Unicode value of an emoji import java.io.*; class Geeks { public static void main(String[] args) { // String with Unicode Created String s = "Geeks for 🤖 Geeks"; // Get the Unicode code point of the // emoji at index 5 int a = s.codePointAt(10); System.out.println("Code point at index 10 : " + a); } } OutputCode point at index 10 : 129302 Example 3: If we attempt to access an invalid index, the codePointAt() method will throw an IndexOutOfBoundsException. Java // Java program to demonstrate IndexOutOfBoundsException import java.io.*; public class Geeks { public static void main(String[] args) { String s = "Geeks"; // Trying to access an invalid index // This will throw IndexOutOfBoundsException int a = s.codePointAt(10); System.out.println("Unicode code point: " + a); } } Output: Note: The exception occurs because the index 10 is beyond the string length (which is 5 in this case).Example 4: To handle the exception correctly, we can use a try-catch block as shown in the below example: Java // Java program to demonstrate // exception handling with codePointAt() import java.io.*; public class Geeks { public static void main(String[] args) { String s = "Geeks"; try { // Trying to access an invalid index int a = s.codePointAt(10); // This will throw IndexOutOfBoundsException System.out.println("Unicode code point: " + a); } catch (IndexOutOfBoundsException e) { // Handling the exception System.out.println("Error: " + e.getMessage()); } } } OutputError: index 10,length 5 Comment More infoAdvertise with us Next Article Java String codePointAt() Method M musklf2s Follow Improve Article Tags : Java Java-Strings Practice Tags : JavaJava-Strings Similar Reads Java String codePoint() Method with Examples A Java string consists of a group of characters and each character is associated with a Unicode point value (alias ASCII value). So to get the Unicode point value of a character in a string we will use the codepoint() method. So in order to move further, we need to know what are the associated Unico 4 min read Java String charAt() Method String charAt() method in Java returns the character at the specified index in a string. The Index of the first character in a string is 0, the second character is 1, and so on. The index value should lie between 0 and length() - 1.If the index value is greater than or equal to the string length or 2 min read StringBuffer codePointAt() method in Java with Examples The codePointAt() method of StringBuffer class returns a character Unicode point at that index in sequence contained by StringBuffer. This method returns the âUnicodenumberâ of the character at that index. Value of index must be lie between 0 to length-1. If the char value present at the given index 2 min read Java Vector elementAt() Method In Java, the elementAt() method is used to fetch or retrieve an element at a specific index from a Vector. It allows to access elements in the vector by providing the index, which is zero-based.Example 1: Here, we use the elementAt() method to retrieve an element at a specified index with an Integer 2 min read StringBuffer codePointCount() method in Java with Examples The codePointCount() method of StringBuffer class is used to return the number of Unicode code points in the specified range of beginIndex to endIndex of String contained by StringBuffer. This method takes beginIndex and endIndex as a parameter where beginIndex is the index of the first character of 3 min read StringBuffer codePointBefore() method in Java with Examples The codePointBefore() method of StringBuffer class is a method used to take an index as a parameter and returns the âUnicode numberâ of the character present before that index. The value of index must lie between 0 to length-1. If the char value at (index â 1) is in the low-surrogate range, char at 2 min read StringBuffer appendCodePoint() Method in Java with Examples appendCodePoint() method of StringBuffer class appends the string representation of the codePoint argument to this sequence for which we require pre-requisite knowledge of ASCII table as then only we will be able to perceive output why the specific literal is being appended as there is already an in 3 min read StringBuilder appendCodePoint() method in Java with Examples The appendCodePoint(int codePoint) method of StringBuilder class is the inbuilt method used to append the string representation of the codePoint argument to this sequence. The argument is appended to this StringBuilder content and length of the object is increased by Character.charCount(codePoint). 2 min read DecimalFormat setRoundingMode() method in Java The setRoundingMode() method is a built-in method of the java.text.DecimalFomrat class in Java and is used to set the RoundingMode to be used with this DecimalFormat instance to round-off the decimal digits. Syntax: public void setRoundingMode(RoundingMode roundingMode) Parameters: The function acce 1 min read MathContext toString() Method in Java The MathContext.toString() method in Java is a part of java.math package. This method is used to define the precision and rounding behaviour for BigDecimal operations. This method returns the string representation of a MathContext object's context settings. The string returned represents the setting 2 min read Like