Javatpoint Logo
Javatpoint Logo

Java String charAt()

The java string charAt() method returns a char value at the given index number. The index number starts from 0. It returns StringIndexOutOfBoundsException if given index number is greater than this string or negative index number.


The signature of string charAt() method is given below:


index : index number, starts with 0


char value

Specified by

CharSequence interface


StringIndexOutOfBoundsException : if index is negative value or greater than this string length.

Java String charAt() method example

Test it Now



StringIndexOutOfBoundsException with charAt()

Let's see the example of charAt() method where we are passing greater index value. In such case, it throws StringIndexOutOfBoundsException at run time.


Exception in thread "main" java.lang.StringIndexOutOfBoundsException: 
String index out of range: 10
at java.lang.String.charAt(
at CharAtExample.main(

Please Share

facebook twitter google plus pinterest tumbler

Learn Latest Tutorials