setCharAt, append, insert, reverse, delete, deleteCharAt StringBuffer methods in Java

setCharAt( ) method: It is used to set the value of character in a StringBuffer.


void setCharAt(int index, char ch)

where, ch is the new value of the character.

append( ) method: append method firsts determines the string representation of any given data and then it appends it to the StringBuffer object.


StringBuffer append(String str)

StringBuffer append(int n)

StringBuffer append(Object ob)

insert() method: It is used to insert a string to another.


StringBuffer insert(int index, String str)

StringBuffer insert(int index, char ch)

StringBuffer insert(int index, Object ob)

index is where the string will be inserted.

reverse() method: It is used to reverse the characters in StringBuffer.


StringBuffer reverse( )

delete( ) method: It is used to delete a character sequence.


StringBuffer delete(int sIndex, int eIndex)

where, sIndex is where the sequence starts and eIndex is where the sequence ends, which needs to be deleted.

deleteCharAt( ) method: It is used to delete a particular character.


StringBuffer deleteCharAt(int index)

Leave a Reply