String charAt() method in java

Let’s learn String charAt() method in java.

String charAt() method in java

charat function in java or charat java returns the char value at the specified index. An index ranges from 0 to length() – 1.

The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.


public char charAt(int index)


index – the index of the char value.


the char value at the specified index of this string. The first char value is at index 0.


IndexOutOfBoundsException – if the index argument is negative or not less than the length of this string.

Now let’s see example on String charAt() method.

public class StringCharAtMethodJava
   public static void main(String[] args)
      String strInput = "Hello World Java";
      char ch1 = strInput.charAt(1);
      char ch2 = strInput.charAt(6);
      char ch3 = strInput.charAt(14);
      System.out.println("Character at 1st index is: " + ch1);
      System.out.println("Character at 6th index is: " + ch2);
      System.out.println("Character at 14th index is: " + ch3);


Character at 1st index is: e
Character at 6th index is: W
Character at 14th index is: v

Also read – java overview

Reference: oracle docs