日期:2014-05-20 浏览次数:20644 次
public static List<Integer> getList(List<Integer> list){ Collections.sort(list, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o1.intValue()-o2.intValue() ; } }); return list ; } public static void main(String[] args) { String s[] = {"{2,3,4,5,21,8,12,23,7,6}","{2,3,4,5,21,8,12,23,7,6,12,13,14,15,211,81,121,231,71,61}"} ; Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>() ; for (int i = 0; i < s.length; i++) { List<Integer> list = new ArrayList<Integer>() ; s[i] = s[i].substring(1, s[i].length()-1); String[] ss = s[i].split(",") ; for (int j = 0; j < ss.length; j++) { Integer integer = Integer.parseInt(ss[j]) ; list.add(integer) ; } list = getList(list) ; map.put(i, list) ; } for (int i = 0; i < s.length; i++) { s[i] ="{" ; int j = 0 ; for (Integer integer : map.get(i)) { if(j == 0) s[i] = s[i]+integer.toString() ; else s[i] = s[i]+","+integer.toString() ; j= j+ 1; } s[i] = s[i]+"}" ; } System.out.println(s[0]+ s[1]); }