Java.lang.String.codePointAt() Method
Advertisements
Description
The java.lang.String.codePointAt() method returns the character (Unicode code point) at the specified index. The index refers to char values (Unicode code units) and ranges from 0 to length() - 1.
Declaration
Following is the declaration for java.lang.String.codePointAt() method
public int codePointAt(int index)
Parameters
index -- This is the index to the char value.
Return Value
This method returns the code point value of the character at the index.
Exception
IndexOutOfBoundsException -- if the index argument is negative or not less than the length of this string.
Example
The following example shows the usage of java.lang.String.codePointAt() method.
package com.tutorialspoint;
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str = "JAVA";
System.out.println("String = " + str);
// codepoint at index 1
int retval = str.codePointAt(1);
// prints character at index1 in string
System.out.println("Character(unicode point) = " + retval);
}
}
Let us compile and run the above program, this will produce the following result:
String = JAVA Character(unicode point) = 65