map 排序

        Map<Integer ,String> map = new HashMap<Integer,String>();
        //map.put();省略 put
   	     List arrayList = new ArrayList(map.entrySet());
       	Collections.sort(arrayList, new Comparator() {
       	   public int compare(Object o1, Object o2) {
       	    Map.Entry obj1 = (Map.Entry) o1;
       	    Map.Entry obj2 = (Map.Entry) o2;
       	    Collator cmp = Collator.getInstance(java.util.Locale.CHINA);//中文排序
               return cmp.compare(obj1.getValue(), obj2.getValue());
       	   }
       	  });
       	  Map<Integer,String> sortMap = new LinkedHashMap<Integer,String>();
       	  for (Iterator iter = arrayList.iterator(); iter.hasNext();) {
       	   Map.Entry entry = (Map.Entry) iter.next();
       	   String  value = (String)entry.getValue();
       	   Integer key = (Integer) entry.getKey();  
           sortMap.put(key, value);
        }




你可能感兴趣的:(java)