codePointAt() - String Method in Java


This article is a part of String Methods in Java.
This method returns the Unicode value of the character at the specified index. Let me tell you if you don`t know already, that the index of the first character of a string is 0. The parameter is of int type, representing the index of the character in the string.


Return type

The return type of the codePointAt() method is int. Let us look at an example code to understand it better.

Example


Output

Let us look at the output of the above example code.

String Methods codePointAt()
Fig.1- String Method - codePointAt()

Here the index = 1 points to the character ā€œeā€, the Unicode value of ā€œeā€ is 101 which is displayed in the output console.

IndexOutOfBound exception in codePointAt()

When we pass negative index or an index greater than length() - 1 then the codePointAt() method throws IndexOutOfBound exception. Let us look at the code for this case.


Output

Let us look at the output of the above example code.

String Methods codePointAt()
Fig.2- String Method - codePointAt() IndexOutOfBound

Since, the index is a negative number the method throws an exception.

Read More

Author : Satyam Kumar -



You will also like:


Snowflake Cloud Data Warehouse

What is Snowflake, and what can you do with Snowflake? In video article.

Learning Journal

Array Concatenation in Java

Learn how to join two or more arrays together in Java by various methods.

Learning Journal

What is Programming and Programming Language

"PROGRAMMING" is the word which we all come across quite often. Let us see what that means.

Learning Journal

Generate Random Number in Java

Look at the different methods to generate random numbers in Java.

Learning Journal

Dawn of Bigdata

Let us go through the birth of Bigdata.

Learning Journal