It returns the char value present in the string at the specified index. Here,  index value can not be greater than length() -1.

Syntax:

Parmeters

It accepts only one parameter that is the index of the character.

Returns

charAt() method returns char value present at the specified index in the string.

Throws:

The method throws IndexOutOfBoundsException if index is negative or greater than the length of the string.

Example 1:

output :

Example 2 :- StringIndexOutOfBoundsException with charAt()

Output:

Example 3 :

Output:

Example 4:

Output:

Example 5:

Output:

Pin It on Pinterest

Share This