Java StringBuffer delete() Method

delete(int startIndex, int endIndex)

delete the substring of the string buffer from startIndex to endIndex-1.

Syntax:

public synchronized StringBuffer 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.

 

Example:

class TestStringBuffer{
    StringBuffer sb = new StringBuffer("Hello www.w3schools.blog");
    
    public void deleteTest(){
        //delete the substring of the string 
                //buffer from startIndex to endIndex-1.
        System.out.println(sb.delete(0,6));
    }
}

public class StringBufferDeleteExample {
    public static void main(String args[]){
        //creating TestStringBuffer object
        TestStringBuffer obj = new TestStringBuffer();
        
        //method call
        obj.deleteTest();
    }
}

Output

www.w3schools.blog