Java StringBuilder delete() method

delete(int startIndex, int endIndex): delete the substring of the string builder from startIndex to endIndex-1.


public StringBuilder delete(int startIndex, int endIndex)


Note: startIndex should be between 0 and to length of the string or less than endIndex, if it is not StringIndexOutOfBoundsException will be thrown.


StringBuilder delete() Example

class TestStringBuilder{
    StringBuilder sb = 
                new StringBuilder("Hello");
    public void deleteTest(){
        //delete the substring of the string 
                //buffer from startIndex to endIndex-1.

public class StringBuilderDeleteExample {
    public static void main(String args[]){
        //creating TestStringBuilder object
        TestStringBuilder obj = new TestStringBuilder();
        //method call