The Java.lang.StringBuffer.deleteCharAt() is a built-in Java method which removes the char at the specified position in this sequence. So that the sequence is reduced by 1 char.
public StringBuffer deleteCharAt(int indexpoint)
Parameters : The method accepts a single parameter indexpoint of integer type which refers to the index of the char to be removed.
Return Value: The function returns the string or returns this object after removing the character.
Exception : If the indexpoint is negative or greater than or equal to length(), then the method throws StringIndexOutOfBoundsException.
Input : StringBuffer = worldofgeeks int indexpoint = 4 Output : worlofgeeks
Below programs illustrate the working of StringBuffer.deleteCharAt() method:
String buffer before deletion = raghav After deletion new StringBuffer = ragha
String buffer before deletion = GeeksforGeeks After deletion new StringBuffer = GeeksorGeeks
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -5 at java.lang.AbstractStringBuilder.deleteCharAt (AbstractStringBuilder.java:824) at java.lang.StringBuffer.deleteCharAt(StringBuffer.java:441) at Geeks.main(Geeks.java:14)
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.