CharAt() Method In Java

You will get the detailed explanation about the charAt() method of String class. We are going for using charAt() method. You can see how to use the method by syntax.

Description of program:

Here, you will understand about the procedure of the charAt() method through the following java program. This program reads a string as input through the keyboard. And first this shows the length of the string then find the character at the 12th (mentioned as a parameter of the method) position of the string that is retrieved by using charAt() method. This method takes a parameter that is the position of the string. The charAt() method returns a character value for the character at the given position of the string.

Here is the code of this program:

import java.io.*;
class CharAtMethod{
  public static void main(String[] args){
  try{
      BufferedReader DataObject=  new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Please Enter Your Name :  ");
      String Char_Data = DataObject.readLine();
      int Data_length = Char_Data.length();
      System.out.println(Data_length);
      char All_Charactor = Char_Data.charAt(12);
      System.out.println(All_Charactor);
  }
  catch(Exception e){}
  }
}