好像也很复杂...
String[] str = {"1", "2", "3", "66", "54", "513", "323", "12", "121"};
Map> map = new HashMap >(); //按照长度区分数据
SetindexSet = new HashSet (); //长度去重
for (String string : str) {
int length = string.length();
Listlist = map.get(length);
if (list == null) {
list = new ArrayList();
}
list.add(string);
Collections.sort(list); //默认排序
indexSet.add(length);
map.put(length,list);
}
ListindexList = new ArrayList ();
for (Integer integer : indexSet){
indexList.add(integer);
}
Collections.sort(indexList); //长度默认排序
JSONArray jsonArray = new JSONArray();
for (Integer integer : indexList){
ListvalueList = map.get(integer);
String[] strings = valueList.toArray(new String[valueList.size()]);
jsonArray.add(strings);
}
System.out.println(jsonArray.toString());
private static List stringGroupO(String[] strs){
List list1 = new ArrayList();
List list2 = new ArrayList();
for(int i=0;i
param.put(strs[i].length(), strs[i]);
list1.add(param);
list2.add(strs[i].length());
}
List newList = new ArrayList(new HashSet(list2));
List resultList = new ArrayList();
for(int j =0;j
for(int k=0;k
if(map.get(newList.get(j)) != null){
list.add(map.get(newList.get(j)));
}
}
resultList.add(list);
}
return resultList;
}