/* * Stringbuilder方法和 StringBuffer方法基本相同 */ package exe.string; public class StringBuilderDemo { /** * @Title * @Description * @param * @return void * @pages * @throws */ public static void main(String[] args) { // TODO Auto-generated method stub //append 方法 StringBuilder sb = new StringBuilder();//默認長度爲16 StringBuilder sb1 = new StringBuilder("abc");// 如今長度爲20 sb1.append("defg"); System.out.println("sb1="+sb1); //replace 方法 sb1.replace(1, 2, "De"); System.out.println("sb1="+sb1); //insert 方法 sb1.insert(2, 'E'); System.out.println("sb1="+sb1); //delete 方法 StringBuilder sb2 = new StringBuilder("abcdefghijklmn"); sb2.delete(2, 5); System.out.println("sb2="+sb2); //reverse 方法 sb2.reverse(); System.out.println("sb2="+sb2); } }