The Java String charAt() method returns the character at the specified index. The index value should lie between 0 and length()-1.
public char charAt(int index)
index- Index of the character to be returned.
returns character at the specified position.
StringIndexOutOfBoundsException- If index is negative or greater then the length of the String.
Example:To show working of charAt() method
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 4 at java.lang.String.charAt(String.java:658) at Gfg.main(File.java:9)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- StringBuilder charAt() in Java with Examples
- CharBuffer charAt() methods in Java with Examples
- Collator compare(String, String) method in Java with Example
- Collator equals(String, String) method in Java with Example
- Java.lang.string.replace() method in Java
- Java String contains() method with example
- Java String isEmpty() method with example
- Java String trim() method with Example
- RuleBasedCollator getCollationElementIterator(String) method in Java
- ZoneOffset of(String) method in Java with Examples
- String toString() Method in java with Examples
- CollationElementIterator setText(String) method in Java with Example
- Split() String method in Java with examples
- Java String subSequence() method with Examples
- Java.lang.String.lastIndexOf() Method
- PrintWriter write(String, int, int) method in Java with Examples
- PrintWriter write(String) method in Java with Examples
- DecimalFormatSymbols setNaN(String) method in Java with Examples
- Writer write(String, int, int) method in Java with Examples
- StringWriter write(String, int, int) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.