String, StringBuffer,StringBuilder 的区别 转至
String 每一次改变都会新生产一个String,
StringBuffer 对string自身的改变;
public static String zipString(String iniString) {
StringBuilder build=new StringBuilder(); char pre=iniString.charAt(0); int count=1; for(int i=1;i<iniString.length();i++) { if(iniString.charAt(i)==pre) { count++; continue; } else{ build.append(pre).append(count); pre=iniString.charAt(i); count=1; } } build.append(pre).append(count); if (build.toString().length()>iniString.length()) return iniString; else return build.toString(); }