/** * 截取字符串 */ public static void testSubStr() { StringBuffer sb = new StringBuffer("This is a StringBuffer!"); // substring方法截取字符串,可以指定截取的起始位置和终止位置, // 默认终止位置为字符串末尾 System.out.println("sb.substring(2) = " + sb.substring(2)); System.out.println("sb.substring(2, 9) = " + sb.substring(2, 9)); }