map倒敘排序


首先 map排序
先是按照插入順序排序 這里使用的是LinkedHashMap

LinkedHashMap<String, String> breadCrumbmap  = getBreadCrumb(id);
		Iterator it = breadCrumbmap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            System.out.println("排序前" + entry.getValue());
        }
		ListIterator<Map.Entry<String, String>> i = new ArrayList<>(breadCrumbmap.entrySet()).listIterator(breadCrumbmap.size());
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap<String, String>();
        while (i.hasPrevious()) {
            Entry<String, String> entry = i.previous();
            linkedHashMap.put(entry.getKey(), entry.getValue());
        }
        Iterator it1 = linkedHashMap.entrySet().iterator();
        while (it1.hasNext()) {
            Map.Entry entry = (Map.Entry) it1.next();
            System.out.println("排序后" + entry.getValue());
        }

  結果為:

排序前第三層
排序前第二層
排序前第一層
排序前首頁
排序后首頁
排序后第一層
排序后第二層
排序后第三層

  


免責聲明!

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



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