Java charAt() Method

Java String类Java String Class


The charAt() method is used to return the character at the specified index. The index range is from 0 to length() - 1.

Syntax

public char charAt(int index)

Parameters

  • index-- The index of the character.

Return Value

Returns the character at the specified index.

Example

Example

public class Test { public static void main(String args[]) { String s = "www.example.com"; char result = s.charAt(6); System.out.println(result); } }

The output of the above program is:

n

Java String类Java String Class

Other Extensions