Java String charAt() Method

Java String charAt()

The charAt() method returns the character at the given index in a string.

The index number starts from 0 and goes to n-1, where n is length of the string.


Java Compiler
public class myClass { public static void main(String[] args) { String str = "Apple"; System.out.print(str.charAt(0)); // A } }


public char charAt(int index)

Parameter Values

indexRequiredSpecifies an index number.

Return Value

CharacterReturns the character at the given index in a string.
ErrorReturns StringIndexOutOfBoundsException, if index number is negative or not less than the length of the given string.

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author