平时开发的一些总结

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(",")));
                }

              

你可能感兴趣的:(java,value,Map排序, )