Java String.codePointAt()

The method codePointAt() takes an int as a parameter and returns the
code point at the specified index. A code point is a decimal value that
the character is given in the Unicode standard.

Available Signatures

public int codePointAt(int index)

Example

@Test
public void whenCallCodePointAt_thenDecimalUnicodeReturned() {
    assertEquals(97, "abcd".codePointAt(0));
}

Throws

  • StringIndexOutOfBoundsException – if a non-existent index is passed
    to the method.

@Test(expected = StringIndexOutOfBoundsException.class)
public void whenPassNonExistingIndex_thenStringIndexOutOfBoundsExceptionThrown() {
    int a = "abcd".codePointAt(4);
}

Next »

« Previous

Leave a Reply

Your email address will not be published.