Java provides two data types for strings. “String” and “StringBuffer”. Use the “StringBuffer” if you need your string to be modifiable. Variables declared as “String” type cannot be changed.
public class T1 { public static void main(String[] args) { String s1 = "some str"; StringBuffer s2 = new StringBuffer(9); s2.replace(0,0,s1); System.out.println(s2.toString()); } }
The replace() is a method of “StringBuffer” classs. It replaces parts (or all) of the “StringBuffer” object by a “String” object.
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html