Java StringBuffer deleteCharAt() Example

Java StringBuffer deleteCharAt() method removes the char at the specified position in this sequence. This sequence is shortened by one char.
This method throws StringIndexOutOfBoundsException - if the index is negative or greater than or equal to length().

Java StringBuffer deleteCharAt() Example

Example: Example to delete character 'g' from string 'javaguides' using deleteCharAt() method.
public class DeleteCharAtExample {
    public static void main(String[] args) {
        StringBuffer buffer = new StringBuffer("javaguides").deleteCharAt(4);
        System.out.println("Delete char 'g' from string 'javaguides' : " + buffer);
    }
}
Output:
Delete char 'g' from string 'javaguides' : javauides

Comments