Storing values

M

Michael

Hi,

I would like to store values in the form of this:

(rootNode, childNode1)
(rootNode, childNode2)
(rootNode, childNOde3)
....

What sort of collection type can I use in this case? I have looked
into Hashtable, and it seems to overwrites to the last inserted data
when providing the same Key (rootNode).

Any help from you guys will be greatly appreciated.

Thank You.
 
T

Tony Morris

Michael said:
Hi,

I would like to store values in the form of this:

(rootNode, childNode1)
(rootNode, childNode2)
(rootNode, childNOde3)
...

What sort of collection type can I use in this case? I have looked
into Hashtable, and it seems to overwrites to the last inserted data
when providing the same Key (rootNode).

Any help from you guys will be greatly appreciated.

Thank You.

You want to use a data structure known as a BTree.
Java does provide support for this ADT in the core API; you'll have to write
it yourself.

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 
B

Bjorn Abelli

...
I would like to store values in the form of this:

(rootNode, childNode1)
(rootNode, childNode2)
(rootNode, childNOde3)
...

What sort of collection type can I use in this case?

That depends on how you actually are going to use the "collection".
I have looked into Hashtable, and it seems to
overwrites to the last inserted data when
providing the same Key (rootNode).

Yes of course, as Hashtable is a collection based on the concept of
"key-value-pair" (*one* key to *one* value), to speed up the search for what
value that is associated to a specific key.

But it doesn't seem like that really is what you want, as you try to store
"children" to a "root", i.e. not a 1:1-relation but a 1:m-relation.

Possibly you're looking for the "other way around":

(childNode1, rootNode)
(childNode2, rootNode)
(childNode3, rootNode)

....which is possible to use as a "lookup" to see which root a child belongs
to (if a child only can belong to one root at a time).

It could also be possible that you really not are looking for a "Collection"
at all, but rather a "datamodel", which it in this case looks like, e.g. a
"TreeModel" such as "DefaultTreeModel".

In the end, which "collection" you need isn't depending on what type you
"can" use, but rather on "how" you will use it.

// Bjorn A
 
A

ak

I would like to store values in the form of this:
(rootNode, childNode1)
(rootNode, childNode2)
(rootNode, childNOde3)
...

What sort of collection type can I use in this case? I have looked
into Hashtable, and it seems to overwrites to the last inserted data
when providing the same Key (rootNode).

I use similar thing in my project ImageroReader - it called HashBag.
it uses simple idea - each key in Hashtable corresponds to Vector which
contains all values for this key.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top