charAt() of String class is a simple method to find out the character at a particular position in the String.
Structure of charAt() looks like
public char charAt(int index)
- Returns the character at a particular index in the String
Lets say for String "Zartab", if i need to find what is the character at index number
So now to get any character at location let say 4, we need to write the code as
String str="Zartab";
char c=str.charAt(4);
System.out.println(c);
c will return 'A'.
The whole will look like
class CharAtDemo
{
public static void main(String[] args)
{
String str="ZARTAB";
char c=str.charAt(4);
System.out.println(c);
}
}
0 comments:
Post a comment