ArrayListHashMap

R

RVic

Hmmm, surely there must be a creature out there -- or, better yet, an
efficient means to utilise an ArrayList of objects, wherein one field
in each object is unique within the ArrayList (similar to a Hash Key)
and you can do rapid lookups on that key.

Is there such an amalgam creature in teh Collections classes? Is there
in the public domain anyone is aware of? Thanks.
 
A

Alessio Stalla

Hmmm, surely there must be a creature out there -- or, better yet, an
efficient means to utilise an ArrayList of objects, wherein one field
in each object is unique within the ArrayList (similar to a Hash Key)
and you can do rapid lookups on that key.

Is there such an amalgam creature in teh Collections classes? Is there
in the public domain anyone is aware of? Thanks.

Do you want something you can use both as an arraylist *and* a map? I
don't think such a datastructure exists in any collection library I
know of. You could implement it as an ArrayList<T> plus a
HashMap<T.key, index> and the necessary bookkeeping.
However, there are operations on this data structure you have to
specify clearly: for example, what does add() do when another object
with the same key is in the list?
 
R

RVince

Thanks Folks,

I have an ArrayList from a set of fields I am parsing coming over a
socket -- an ArrayList of complicated, nested, nasty objects..gobs of
goop. I think my best recourse here is to put them into a HashMap by
unique key, adding an element to the object of the order they would
have gone into the ArrayList, should I need to sort them later by
order received. Thanks so much.
 
L

Lew

Ah yes...precisely what I need Patricia! Thanks.

In future, consider perusing the Javadocs at the package level, in
this case java.util. You get a summary of the classes in that
package. Perhaps LinkedHashMap or one of its brethren (e.g., TreeMap)
would have caught your eye, then you would have looked up the class
docs to see if they suited your purpose.

How do you think others discover these classes?

If the Javadocs aren't friendly enough, GIYF.
 
R

Roedy Green

and you can do rapid lookups on that key.

Is there such an amalgam creature in teh Collections classes? Is there
in the public domain anyone is aware of? Thanks.

Just use two Collections.

There is a bit of a problem meshing since ArrayLists are happy with
duplicates and HapMaps are not.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Let us pray it is not so, or if it is, that it will not become widely known."
~ Wife of the Bishop of Exeter on hearing of Darwin's theory of the common descent of humans and apes.
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,171
Latest member
VinayKumar Nevatia__
Top