StringBuffer和String,StringBuffer的replace会改变自己,String的replace不会改变自己,使用new StringBuffer可以构造多个值相同的字符串对象
String的replace不会改变原来的String,会新增一个String
String str = "abcdefg";
String re = str.replace("c","c2");
StringBuffer的replace会改变原来的StringBuffer,会替换起始位置到结束位置的字符串,替换下标1,2,不替换下标3
StringBuffer sb = new StringBuffer(str);
sb.replace(1,3,"hh");
复制字符串,两块内存
String str = "abcdefg";
StringBuffer sb = new StringBuffer(str);
StringBuffer sb2 = new StringBuffer(str);