charAt In Java Example
Chapter:
String Handling
Last Updated:
10-06-2016 16:48:24 UTC
Program:
/* ............... START ............... */
public class JavaCharAtExample {
public static void main(String args[]) {
String str = "Java Char At Example ";
char ch1 = str.charAt(0);
char ch2 = str.charAt(7);
char ch3 = str.charAt(13);
System.out.println("Character at 0 index is: " + ch1);
System.out.println("Character at 5th index is: " + ch2);
System.out.println("Character at 11th index is: " + ch3);
}
}
/* ............... END ............... */
Output
Character at 0 index is: J
Character at 5th index is: a
Character at 11th index is: E
Notes:
-
The method charAt(int index) returns the character at the specified index.
- If the index argument is negative or not less than the length of this string then it will throw IndexOutOfBoundsException exception.
Tags
charAt(), Java