Map<String,Map<String,Integer>> result=new ConcurrentHashMap<String,Map<String,Integer>>();
map嵌套map 里面的map根据value排序
//降序
for(String key:result.keySet()){ int count=0; StringBuffer sb1=new StringBuffer(); Map<String,Integer> map=result.get(key); List<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return (o2.getValue() - o1.getValue()); } }); for(int i=0;i<list.size();i++){ Entry<String,Integer> en=list.get(i); sb1.append(en.getKey()+","+en.getValue()+","); count+=en.getValue(); } String str1 = starttime+","+interval+","+key+","+count+","+sb1.toString(); System.out.println(str1.substring(0, str1.lastIndexOf(","))); }
本文出自 “Developer_Road” 博客,请务必保留此出处http://jiangdf.blog.51cto.com/6425070/1697317
原文地址:http://jiangdf.blog.51cto.com/6425070/1697317