Replace( )

Another new method added to String Buffer by Java 2 is replace ). It replaces one set of characters with another set inside a String Buffer object. Its signature is shown here: I String bluffer replace(int standstill, int extender, String str) , The sub string being replaced is specified by the indexes start index and endurance. Thus, the sub string at startle through extender-l is replaced. The replacement string is passed in str. The resulting String Buffer object is returned. . The following program ?,remonstrates replace( ):

Here is the output: After replace This was a test

sub string( )

Java 2 also adds the sub string( ) method, which returns a portion of a String Buffer. It· has the following two forms: String sub string(int start Index) String sub string(int start index, int end index) TI,e first form returns the sub string that starts at start index and runs to the end of the invoking String Buffer object. The second form returns the sub string that starts at . start Jesuit and runs through end index-A. These methods work just like those defined for String that were described earlier.

[vfb id=1]

Share This