delete(int startIndex, int endIndex) StringBuilder method in java

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 to length of string or less than endIndex, if it is not StringIndexOutOfBoundsException will be thrown.


 * This program is used to show the use of delete() method.
 * @author w3spoint
class TestStringBuilder{
	StringBuilder sb = 
                new StringBuilder("Hello");
	 * This method is used to show the use of delete() method.
	 * @author w3spoint
	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


Download this example.
Next Topic: reverse() StringBuilder method in java.
Previous Topic: replace(int startIndex, int endIndex, String str) StringBuilder method in java.


Please Share