JDK-6182958 : (coll) Add an entryList() method to LinkedHashMap
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 5.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-10-21
  • Updated: 2012-10-08
Description
A DESCRIPTION OF THE REQUEST :
Linked hashmap is described in the documentation as "Hash table and linked list implementation of the Map interface" but there is no way to view a linked hashmap as a list of entries.

JUSTIFICATION :
The linked hashmap implementation use linked list, but there is no easy way to view it as a list. So if you use a third party code that need list, the simple
way to do this actually is to use a temporary list.

In swing application, the use temporary list breaks the design pattern MVC and transform the simple fact to view (on screen) a linked hash map into a JList
in a nightmare.

Another justification, there is no way to iterate on entries in backward order even if the current implementation permit this.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Add a method entryList() in the LinkedHashMap class.

proposed signature :
public List<Map.Entry<K,V>> entryList();
the returned List may implements SequentialList.

  To be symetric, a method entryList() could be added to LinkedHashSet
public List<E> asList();
ACTUAL -
view as an entry list :

LinkedHashMap<String,String> map=new LinkedHashMap<String,String>();
LinkedList<Map.Entry<String,String>> list=
  new  LinkedList<Map.Entry<String,String>>();
list.addAll(map.entrySet());
###@###.### 10/21/04 23:29 GMT