The insert ) method inserts one string into another. It is overloaded to accept values of all the simple types, plus Strings and Objects. Like append(), it calls String value of( ) to obtain the string representation of the value it is called with. This string is t~en inserted into the invoking String Buffer object. These are a few of its forms:
- String Buffer insert(int index, String str)
- String Buffer insert(int index, char ell)
- String Buffer insert(int index, Object obj)
Here, index specifies the index at which point the string will be inserted into the invoking String Buffer,object. The following sample program inserts “like” between :T’ and “Java”: The output of this example is shown here: , I like Java!
You can reverse the characters within a String~objectifying reverse! ), shown here: String Buffer reverse() . This method returns the reversed object on which it was called. The following program demonstrates reverse( ): Here is the output produced by the program:
Abrade feedbag delete( ) and delete Char At( ) . Java 2 adds to String Buffer the ability to delete characters using the methods delete] ) and delete Char At( ). These methods are shown here: – . String buffer delete-tint starring, int extender String Buffer delete Char At(int lac) . The delete( ) method deletes a sequence of characters from the invoking object. Here, standstill specifies the index of the first character to remove, and an index one past the last character to remove. Thus, the sub string deleted ,from standstill to end index-L, The resulting String Buffer object is returned. ‘The delete Char At() method deletes the character at the index specified it returns the resulting String bluffer object. Here is a program that demonstrates the delete( ) and delete Char At( ) methods: The following output is produced: After delete: T~is a test. After delete Char At: his a test .