/** * 替换字符串中的某些字符 */ public static void testReplace() { StringBuffer sb = new StringBuffer("This is a StringBuffer!"); // 将字符串中某段字符替换成另一个字符串 sb.replace(3, 8, "replace"); System.out.println("testReplace: " + sb.toString()); }