CodesJava

Easy learning with example program codes

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

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

Example:

StringBufferDeleteExample.java

/**
 * This program is used to show the use of delete() method.
 * @author codesjava
 */
class TestStringBuffer{
	StringBuffer sb = new StringBuffer("Hello www.codesjava.com");
 
	/**
	 * This method is used to show the use of delete() method.
	 * @author codesjava
	 */
	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.codesjava.com

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

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status