Java StringBuilder deleteCharAt() Method
Example
Remove the exclamation mark from a StringBuilder:
StringBuilder sb = new StringBuilder("Hello!");
sb.deleteCharAt(5);
System.out.println(sb);
Definition and Usage
The deleteCharAt() method removes the character at the specified index. The characters after it move one position to the left.
Tip: Use delete() to remove more than one character.
Syntax
public StringBuilder deleteCharAt(int index)
Parameter Values
| Parameter | Description |
|---|---|
| index | Required. The index of the character to remove. |
Technical Details
| Returns: | The same StringBuilder, with the character removed. |
|---|---|
| Throws: | StringIndexOutOfBoundsException - if index is negative or not less than the length. |
Related Pages
❮ StringBuilder Methods