logo

Java String CharAt() Method


Show

Description

This process returns the quality placed at the String's precise index. The string indexes create from zero. The java string charAt() way returns a char significance at the agreed index number. The index number begins from 0 and goes to n-1, where n is the length of the thread. It returns StringIndexOutOfBoundsException if the known index number is better than or equivalent to this string span or a negative number.

Syntax

Here is the syntax of this method:

public char charAt(int index)

Parameters

Here is the detail of parameters −

  • index − Index of the character to be returned.

Return Value

  • This method returns a char at the specified index.

Example

public class Test {

   public static void main(String args[]) {
      String s = "Strings are immutable";
      char result = s.charAt(8);
      System.out.println(result);
   }
}

This will produce the following result:

Output

a

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.