當前位置:成語大全網 - 書法字典 - java中如何遍歷HashMap的逆序,如何解決

java中如何遍歷HashMap的逆序,如何解決

case//遍歷HashMap逆序

公共靜態void main(String[] args) {

LinkedHashMap & ltString,String & gtlinked hashmap = new linked hashmap & lt;String,String & gt();

linkedhashmap.put("1 "," a ");

linkedhashmap.put("2 "," b ");

linkedhashmap.put("3 "," c ");

linkedhashmap.put("4 "," d ");

ListIterator & lt地圖。Entry & ltString,String & gt& gtI =新數組列表& lt地圖。Entry & ltString,String & gt& gt(linkedhashmap.entrySet())。list iterator(linked hashmap . size());

while(i.hasPrevious()) {

地圖。Entry & ltString,String & gtentry = I . previous();

system . out . println(entry . getkey()+":"+entry . getvalue());

}

}

結果: