日期:2014-05-20 浏览次数:20569 次
public static void main(String[] args) { String str = "你好,去,不错,可以,有意思,过来"; int length = 5; String[] arr = str.split(","); List<String> strList = new ArrayList<String>(); String temp = ""; int size = 0; for(String s : arr) { if(temp.equals("")) { if(s.length() > length) { strList.add(s); } else { temp = s; size = s.length(); } } else { if(size + s.length() > length) { strList.add(temp); temp = s; size = s.length(); } else { temp += "," + s; size += s.length(); } } } if(!temp.equals("")) { strList.add(temp); } for(String s : strList) { System.out.println(s); } }