Home Java Beginners charAt() Method In Java

 
 

Share on Google+Share on Google+

charAt() Method In Java

Advertisement
In this section, you will get the detailed explanation about the charAt() method of String class.

charAt() Method In Java

     

In this section, 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. There is a section provided for understanding the usage of the method practically.

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 4th (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 CharAt{
  public static void main(String[] args){
  try{
  BufferedReader object=
  new 
BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the String");
  String s=object.readLine();
  int len=s.length();
  System.out.println(len);
  char char1=s.charAt(4);
  System.out.println(char1);
  }
  catch(Exception e){}
  }
}

OOutput this program:

C:\java_work>java CharAt
Enter the String
roseindia
9
i
C:\java_work>

Download this example.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 5, 2007

Related Tutorials

Discuss: charAt() Method In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:5
Anonymous
February 20, 2012
Nice

Thank you
me and you
October 25, 2011
pen15

I <3 this website
sharavanaguru
January 30, 2012
regardin the post

nice :)
mary
August 9, 2012
Java

how can i use it?
asaness
August 22, 2012
BIN

C:\Program Files\Java\jdk1.6.0_06\bin
DMCA.com