java - How to traverse Linked Hash Map in reverse? -
java - How to traverse Linked Hash Map in reverse? -
possible duplicate: iterating through linkedhashmap in reverse order
how traverse linked hash map in reverse order? there predefined method in map that?
i'm creating follows:
linkedhashmap<integer, string> map = new linkedhashmap<integer,string>(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three");
list<entry<integer,string>> list = new arraylist<>(map.entries()); for( int = list.size() -1; >= 0 ; --){ entry<integer,string> entry = list.get(i); }
not pretty , @ cost of re-create of entry set, if map has important number of entries might problem.
the excellant guava library have [list.reverse(list<>)][2]
allow utilize java 5 each style loop rather indexed loop:
//using guava for( entry entry : lists.reverse(list) ){ // much nicer }
java reverse linkedhashmap
Comments
Post a Comment