Java Tutorial Java Advanced Java Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Java - String codePointAt() Method



The Java string codePointAt() method returns the character (Unicode code point) at specified index in the given string. An index argument must be in the ranges from 0 to length() - 1.

Syntax

public int codePointAt(int index)

Parameters

index specify the index number of the character in the given string.

Return Value

Returns the character (Unicode code point) at specified index in the given string.

Exception

throws IndexOutOfBoundsException, if the index argument is negative or not less than the length of the string.

Example:

In the example below, codePointAt() method returns the character (Unicode code point) at specified index in the string called MyString.

public class MyClass {
  public static void main(String[] args) {
    String MyString = "Hello World!.";
    System.out.println(MyString.codePointAt(1));   
  }
}

The output of the above code will be:

101

❮ Java String Methods

5