Looking for a flexible data structure. Hesitating between Hashmap and others ...

Julien Bayle's icon

Hi there,
I'd need a JAVA equivalent of C++ Map.
I don't care about the sort/order in the structure.
I just need to retrieve easily objects or values stored by using an ID.

I have to able to remove stuff too without letting my structure increasing to the infinite..

any suggestions ?

Julien Bayle's icon

Sysex answered:

Hi,

I don't know what you really want to archive but why using a Hashmap? You could put the reference to the MaxBox-Instance in myObject as field and store the instances of myObject in something that implements the List Interface, like ArrayMap. In case of a HashMap what would be your key (I guess the values will be the myObjects) ?.

What would be the benefits to use ArrayMap over HashMap ?
Indeed, I can store the ref inside the object itself.
Actually the key was a number incremented each time I created on MaxBox and, this is an important value because I'm instantiating my MaxBox (basically pre-made abstractions) with that value as argument, propagating inside the abstraction by #1 ..