Regd LinkedHashMap
1 posts in topic
Flat View  Flat View

Posted By:   a_a
Posted On:   Thursday, October 11, 2001 01:47 PM

I want to retreive the elements in the
HashTable in the order they are entered

I know that java 1.4 has LinkedHashMap
for this purpose.

I cannot port my application to
Java 1.4 right now since some features are different like JPopUpMenu etc.

I wanted to know if there is any other way to do this

I would like to know If anybody
has implemented a custom Hashtable
to return the elements in the order


Re: Regd LinkedHashMap

Posted By:   George_McKinney  
Posted On:   Monday, October 15, 2001 02:14 PM

I implemented a LRU Cache that has more or less the functionality you want. I think that you need to be a bit more specific about the req's though. For instance, what happens if you put() an entry for which the key already exists, and does an access change the order of the iteration?

If you only want to iterate over the Map.Entry Set, I'd just extend HashMap to

1: have an ArrayList of Map.Entry

2: Override put(key, val) (and any other methods or constructors needed) to test for the existence of the key, and if it isn't in the HashMap, create a new Map.Entry, add that to the ArrayList and also call the superclass put()

3: Override entrySet() to return the ArrayList.

This is off the top of my head, so no guarantees, but I think it's close.

About | Sitemap | Contact