Java String charAt example

String's charAt method returns char value present at specified index. String is nothing but Sequence of char values and it starts with index 0.

Method Signature:

public char charAt(int index)

String charAt Example:

package org.arpit.java2blog;

public class StringCharAtMain {

   * @Author : Arpit Mandliya
 public static void main(String args[])
  String str="java2blog";
  System.out.println("char at index 5 :"+str.charAt(5));
  System.out.println("char at index 7 :"+str.charAt(7));

When you run above program, you will get below output:
char at index 5 :b
char at index 7 :o

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus


Java tutorial for beginners Copyright © 2012