Map map按key值排序


    private static String buildMd5Params(Map<String, String> map) {
        StringBuilder result = new StringBuilder(256);
        Map<String, String> sortedMap = new TreeMap(new Comparator<String>() {
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);  //按升序排列 ,改為按降序排列return o2.compareTo(o1); 
            }
        });
        sortedMap.putAll(map);
        Map.Entry<String, String> me = null;
        String val = null;
        Iterator it = sortedMap.entrySet().iterator();

        while(it.hasNext()) {
            me = (Map.Entry)it.next();
            val = (String)me.getValue();
            if (val != null) {
                val = val.trim();
                if (!"".equals(val)) {
                    result.append(val);
                }
            }
        }

        return result.toString();
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM