1The charAt() method returns the character at the specified index in a string.
2The index of the first character is 0, the second character is 1, and so on.
3String myStr = "Hello";
4char result = myStr.charAt(0);
5System.out.println(result);
6o/p:
7H
1// String charAt() method in java example
2public class StringCharAtMethodJava
3{
4 public static void main(String[] args)
5 {
6 String strInput = "HelloWorldJava";
7 char ch1 = strInput.charAt(1);
8 char ch2 = strInput.charAt(6);
9 char ch3 = strInput.charAt(10);
10 System.out.println("Character at 1st index is: " + ch1);
11 System.out.println("Character at 6th index is: " + ch2);
12 System.out.println("Character at 10th index is: " + ch3);
13 }
14}