日期:2014-05-20 浏览次数:20704 次
String s = "qwerrfghh"; StringBuffer news = new StringBuffer(); char c = s.charAt(0); char d; int len = 0; news.append(c); for(int i=1; i<s.length(); i++) { d = s.charAt(i); if(c == d) news.append(d); else { c = d; news.append(",").append(d); } } System.out.println("用逗号分割后的字符串:"+news.toString()); String sb[] = news.toString().split(","); for(int i=0; i<sb.length; i++) { if(sb[i].length() > len) len = sb[i].length(); } System.out.println("最长字符串长度:"+len); System.out.println("最长字符串有:"); for(int i=0; i<sb.length; i++) { if(sb[i].length() == len) System.out.println(sb[i]); }