Java String charAt()


The java stringcharAt() 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.


Signature

The signature or syntax of string trim method is given below:

public char charAt(int index)



Parameter

index : index number, starts with 0


Returns

char value


Specified by

CharSequence interface


Throws

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


Java String charAt() method example

Flash soon



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.

Flash soon



Copyright 2017 Design& Development