pTutorial

New way to learn Programming

Java String charAt method

The charAt() method belongs to the java.lang.String class. It returns a char value at the given index integer. The index always starts from 0. All the details of the charAt method are following below.

Signature of charat


public char charAt(int index)  

Parameter

index : Integer (Starts from zero)

Return Type

Char Value

Throws

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

Java String charAt method example

public class ExampleCharAt{
  
public static void main(String …s){  

String name="ptutorial";  

char ch=name.charAt(2);
 
System.out.println(ch);  

     }
}  

Output

u 

Java String charAt method example

public class ExampleCharAt1{
  
public static void main(String...s){  

String name="ptutorial";  

for(int i=0;i<name.length();i++)
System.out.println(name.charAt(i));  

     }
}  


Output

p
t
u
t
o
r
i
a
l

See Also


QUOTES OF THE DAY

Beauty is truth, Truth beauty- That is all

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER