2020-04-13

Java String charAt() method

String charAt() method


Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.
If the char value specified by the index is a surrogate, the surrogate value is returned.

Java Program Example:


class StringCharAtExample{
public static void main(String args[]){
String str = "String Example";
System.out.println("Chat At 0 index is - " + str.chatAt(0));
}
}

Output:

Chat At 0 index is - S


Method Signature:

public char charAt(int index)

Specified by:
charAt in interface CharSequence

Parameters:
index - the index of the char value.

Returns:
the char value at the specified index of this string. The first char value is at index 0.

Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string

No comments:

Post a Comment