The charAt()
method in Java returns a string character from a specified index.
The syntax of this method is as follows:
string.charAt(index)
The charAt()
function takes one integer parameter that is the index from which the character needs to be extracted.
The return value is a character from the specified index.
In the code below, the character E
is extracted from the string s
with the help of the charAt()
method.
// extacting the character from 11th index of the stringclass string {public static void main( String args[] ) {String s = "Welcome to Educative";char ch = s.charAt(11);System.out.println(ch);}}