首先 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());
}
結果為:
排序前第三層 排序前第二層 排序前第一層 排序前首頁 排序后首頁 排序后第一層 排序后第二層 排序后第三層
