Java StringBuilder deleteCharAt() Method Example

Java StringBuilder 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 a length().

Java StringBuilder deleteCharAt() Method Example

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

Reference

Comments