Follow on Facebook

Like and Share on Facebook

Saturday, January 24, 2015

Java String charAt


Java String "charAt"

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

Signature

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

public char charAt(int index)

Parameter

index : index number, starts with 0

Returns

char value

Specified by

CharSequence interface

Throws

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

Java String charAt() method example

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

Output: t

No comments:

Post a Comment