Java StringBuilder charAt() Method
Example
Return the first character (0) of a StringBuilder:
StringBuilder sb = new StringBuilder("Hello");
char result = sb.charAt(0);
System.out.println(result);
Definition and Usage
The charAt() method returns the character at the specified index in a StringBuilder.
The index of the first character is 0, the second character is 1, and so on.
Tip: Use setCharAt() to change a character.
Syntax
public char charAt(int index)
Parameter Values
| Parameter | Description |
|---|---|
| index | Required. An int value representing the index of the character to return. |
Technical Details
| Returns: | A char value at the specified index. |
|---|---|
| Throws: | IndexOutOfBoundsException - if index is negative or not less than the length. |
Related Pages
❮ StringBuilder Methods