Java String Function charAt()

Java String Function charAt()
Java String Function charAt()

The java string charAt() method returns a char value at the given index number.

The index number starts from 0 and goes to n-1, where n is length of the string. It returns StringIndexOutOfBoundsException if given index number is greater than or equal to this string length or a negative number.

Java String charAt() method example

public class CharAtExample{  
public static void main(String args[]){  
String name="efaculty";  
char ch=name.charAt(2);//returns the char value at the 4th index  
System.out.println(ch);  
}}  

Output:

a
Recent Posts