11 May String chartAt() method in Java
The charAt(int index) method in Java returns character at the specified index.
Syntax
Let us see the syntax,
1 2 3 |
public char charAt(int index) |
Parameters
Let us see the parameters,
- index – Set the index of the character to be returned.
Example
The following is an example of charAt(int index),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class StudyopediaDemo { public static void main(String args[]) { String str = "Welcome to Studyopedia!"; char c = str.charAt(5); System.out.println(str); System.out.println("The character is "+c); } } |
Output
The following is the output,
No Comments