I need a list to store pairs of short strings with the ability to use either string to return the other (kind of like a map). Say the stings are an IP address and the other a computer name. I'd like to be able to do something like:
String name = getName(ipAddr); and
Sting ipAddr = getIP(name);
I'd also like to be able traverse the entries to get each ipAddress;
Is there a java list that has this capability or should I roll my own? Right now, for testing, I'm using HashTable. I think that accessing the list should be thread safe as well - but I've not learned enough about that yet.
My list will be small, probably less than half a dozen entries.
I don't think there is a Java Class that supports a key - key relationship like you want. You could force this, as you mentioned using the methods in either HashMap or Hashtable, but it wouldn't be pretty....some kind of mess of contains()...etc.
I think I would either just maintain 2 HashMaps (one in each direction)...or just make up my own Class that utilized 2 HashMaps to store your data
I'm not real excited about this solution....and it seems like too much work for only a dozen or so entries...hmmm.