by Dinesh Thakur

charAt():- This is a predefined method of String class present in java.1ang package. It used to extract a specify character from a string by the particular index supplied by the programmer and the index must be within the length of the String.

Syntax:- public char charAt(int index)

Algorithm for CharAt():

step 1: read string a

step 2: initialize i=0

step 3: repeat through step-5 while (i < a.length())

step 4: print i is a.charAt(i)

step 5: i=i+ 1

step 6: exit

Here is the Java Example for CharAt():

import java.util.*;

public class charAt
               static void AtChar()
                    System.out.print("Enter a Sentence : ");
                    Scanner s=new Scanner(;
                    String a=s.nextLine();
                         for (int i=0; i<a.length();i++)
                                    System.out.println("char " + i + " is " + a.charAt(i) );
                    public static void main(String[] args)

CharAt() in Java Example