Link to home
Start Free TrialLog in
Avatar of ibo
ibo

asked on

LinkedHashMap equivalent for JDK 1.3

Im looking for alternative implementation for LinkedHashMap so that my code will work with JDK 1.3. (LinkedHashMap was introduced in 1.4). do u guys know if there are already made code for this (before i try to roll my own). Does the Trove Collection classes have the equivalent? Thanks!
Avatar of zzynx
zzynx
Flag of Belgium image

Can't you just copy/paste the code of LinkedHashMap?
Avatar of ibo
ibo

ASKER

ive tried that. but it uses protected classes/attributes of HashMap, so i copy-pasted HashMap, then again HashMap requires another protected code from another class, which means i have to copy another class again. I think that would be my last resort if i didnt find any other alternative solution.
ok Use Vector, and for your object to be collected into this vector make sure u have implemented:

 public boolan equals(Object obj)

to be used in:

Vector.contains()
Vector.indexOf()
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or you could maintain both a list and a map, something like:

public class ListMap
{
   List list = new ArrayList();
   Map map =  new HasMap();

   void add(Object key, Object o)
   {
      map.put(key, o);
      list.add(key);
   }

   Object get(Object key)
   {
      return map.get(key);
   }

   Iterator iterator()
   {
     return list.iterator();
   }

   ..
}