Key/Value list, what is the best way to implement it ?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ed_Ox
Posted On:   Tuesday, September 18, 2001 08:52 AM

Hi, this might be a beginner question, but it's mine...


I need to store a simple key/value list.


Keys are always Strings and associated values can be anything (Object)


I need:

-to know if a key is in the list

-to retrieve the value matching a given key


Array, Vector, Hastable, ...

which one will best suits my needs ??


Note: Speed is more important for me than memory


Thanks

Re: Key/Value list, what is the best way to implement it ?

Posted By:   Axoy_Dhanak  
Posted On:   Tuesday, September 18, 2001 10:36 AM

I use java.util.TreeMap extensively for the exact purpose stated by you. It has all the requisite methods and the ones matching your need are .containsKey(Object key) and .get(Object key).

Re: Key/Value list, what is the best way to implement it ?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, September 18, 2001 10:32 AM

Ed,

You need a Map.

You should take a look at the javadoc java.util.Map interface, and use one of the objects that implements it.

I would suggest you to take a look at java.util.HashMap or java.util.TreeMap. They are both implementing Map but the second one (TreeMap) is an ordered map.
About | Sitemap | Contact