Java StringBuffer example to delete a String in a StringBuffer at the specified position
By candid | Posted :
Nov 11, 2016
| Updated :
Nov 11, 2016
public StringBuffer delete(int start,int end)
Removes the characters in a substring of this sequence. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. If start is equal to end, no changes are made.
Program:
package com.candidjava;
public class StringBufferDelete
{
public static void main(String[] args)
{
StringBuffer sb = new StringBuffer("Students");
sb.delete(3, 5);
System.out.println(sb);
}
}
Output:
Stunts
Description:
A set of characters are deleted from the StringBuffer using index positions.
Parameters:
start - The beginning index, inclusive.
end - The ending index, exclusive.
Returns:
This object.
Throws:
StringIndexOutOfBoundsException - if start is negative, greater than length(), or greater than end.