The charAt() Method:
This method is used to extract a single character from a string at given index number. Index number of the first character starts from 0 including space
Syntax Of charAt() Method:
The signature of charAt() Method is given Bellow:
public char charAt(int indexNumber)
Here indexNumber is the position of the character which you want to obtain. It is however important that the indexNumber should be a position number that start from 0.
Parameter:
index : index number, starts with 0.
Throws:
IndexOutOfBoundsException : if index is negative value or greater than this string length.
Consider the following examples:
class CharAtTest
{
public static void main(String arg[])
{
String s="Java Programing";
System.out.println(s.charAt(5));
}
}
OUTPUT:
P
0 comments:
Post a Comment