java tutorial - Java Strings charAt() method - java programming - learn java - java basics - java for beginners
Description
Java - The charAt () method — returns a character at the specified line index. The string indices in Java start from scratch.
Syntax
The syntax of the method is:
public char charAt(int index)
click below button to copy the code. By - java tutorial - team
Options
Detailed information about the parameters:
- index is the index of the character to retrieve from the string array.
Return value
- In Java, charAt () returns a character from the string array at the specified index.
Sample Code
public class Test {
public static void main(String args[]) {
String s = "Wikitechy is a good Learner Website!";
char result1 = s.charAt(7);
char result2 = s.charAt(11);
System.out.println("The seventh character of the string - " + result1);
System.out.println("The eleventh character of the string - " + result2);
}
}
click below button to copy the code. By - java tutorial - team
Output :
The seventh character of the string - h
The eleventh character of the string - s