CODE
class StringBufferDeleteExample
{
public static void main(String arg[])
{
StringBuffer firstWord = new StringBuffer("Bharat");
System.out.println(firstWord);
firstWord.delete(1, 4);
System.out.println(firstWord);
firstWord.deleteCharAt(0);
System.out.println(firstWord);
}
}
Bharat
Bat
at
This program shows how to delete a character or set of characters from a StringBuffer
object. The first output line Bharat is just the display of contents of firstWord
. The second output line Bat is obtained by deleting a substring
from Bharat
using delete(startIndex, endIndex)
. The substring(1, 4) i.e har
is deleted from Bharat to get Bat.
The third output at is obtained by deleting the first character of Bat using deleteCharAt(0)
. The character at zero position is deleted.
1
are deleted
firstWord.delete(1, 4);</br>
System.out.println(firstWord);