Is there a Collection class that allows a key and two values?
Hi all
Ideally I would like a Collection implemenentation that allows two values for each key rather than just a key/value pair. Does anyone know how I can do this? For example if the key was someone's passport number, value 1 would be their name and value 2 would be their age.
If not I guess I will have to represent the data in a different way - a DOM object for example. But this seems a bit excessive for what I want.
Many thanks
Jon
[470 byte] By [
JonHead34a] at [2007-11-26 17:22:08]

> value 1 would be their name and value 2 would be their age.Those properties should be encapsulated in a class.~
Right, sounds like a Passport class.Why do people like dealing with primitives so much?%
In my understanding that would actually be contra to the purpose of the api in question, but as the other poster pointed out there are lots of ways to do it.
public class MyClass{
private int thingID ;
private String thingName ;
private String thingDescription ;
}
...
HashMap myClassMap() ;
while( [i have more instances to store[ ){
myClassMap(new Integer(thisThingID, thisThing) ;
}
Very rough around the edges but you should get the idea.
Hope this helps,
PS.
> Very rough around the edgesThat's a bit of an understatement...~
*beats yaw over the head with a handy goal stick*Wiseass
> *beats yaw over the head with a handy goal stick*> > WiseassI'm with Yawmark here! :-Pkind regards,Josps. what Duffy indicated is the way to go here.
Wow - 6 replies already!!Many thanks guys - this is extremely helpful!ThanksJon
> Why do people like dealing with primitives so much?
Object technology is a fancy one, and is tough for young procedural programmers to get a good grasp on without some effort. Moreover, good Object technology education is hard to find in computer science programs. Tenured CS professors tend to stick to what they knew rather than something new, in my opinion.
However, Object technology is effectively taught in some Information Systems programs. Programmers that enroll in Information Systems programs at the graduate level tend to be better off in the end. :oP
> Wow - 6 replies already!!
>
> Many thanks guys - this is extremely helpful!
Yep, that's the way we are; there's one thing we all share: we're fast.
We're fast and accurate; I mean there are *two* things we share: we're
fast, accurate and concise ... erm, we share *three* characteristics
here: we're fast, accurate, concise and extremely handsome ...
Oh, I can't do this ;-) Just follow Duffy's advice: construct a little class
that can be used as the 'value' for the <key, value> entries in your map.
All that "number 1 is this, number 2 is that, number 3 is such and so"
etc. is just Fortran legacy.
kind regards,
Jos
> Just follow Duffy's advice...Yawmark's, too (reply #1).~Yawmark (<-- fast, accurate, concise, extremely handsome, and desperately seeking credit ;o)
> > Just follow Duffy's advice...
>
> Yawmark's, too (reply #1).
Yep, you're right; I overlooked your single line, hardly noticable little
reply. You should *sell* yourself a bit more; take it from me ;-)
> ~Yawmark (<-- fast, accurate, concise, extremely handsome, and desperately seeking credit ;o)
Jos (<-- fast, accurate, concise, extremely handsome, gives credit where
credit's due and extremely hungry but my wife gave me a kitchen restraining
order after last week's mess I made so I guess I just go out and get me
some Greek or Tai food or maybe I'll sneakily fry me some eggs with
some French blue cheese on top; I'm sure I can do that easily ;-)
> Yep, you're right; I overlooked your single line,> hardly noticable little reply. It's that whole concisitudinaceousness for which I'm striving.~
> > Yep, you're right; I overlooked your single line,
> > hardly noticable little reply.
>
> It's that whole concisitudinaceousness for which I'm striving.
Erm, that would be three times the word value, no matter where you put
it (if it fits on the board at all ;-)
I've got a culinary tip: never *ever* attempt to fry eggs in French blue
cheese: that stuff just won't melt properly, i.e. first it goes *sizzle, sizzle*
and then it starts to go stinky.
If, in a second attempt, you put bits of French blue cheese on top of your
eggs when they're almost done, it *does* melt properly, I don't know why
yet, because I ran out of eggs (they tasted quite ok though).
I managed to scrape off those stinky black chips but to be certain I've
hidden that pan in the barn for now (temporary solution).
I already knew this, but this little experiment showed it again: cooking is
voodoo and not to be understood. ;-) I satisfied my hungry feeling
after I found a whole fresh package of chocolate cookies (not in the
kitchen so I didn't violate any kitchen restraining order any further).
kind regards,
Jos ;-)
The eggs act as a buffer (temperature wise) between the cheese and the pan. Things like cheese and chocolates don't like direct heat (Try putting a bar of baker's chocolate in a frying pan and watch what happens) It's not pretty I did it once when I was about 12. Hey I wanted to make my own candy bar. At least I didn't blow the house up. Just made a really nasty mess.
More relevantly though (unlike most of the drivel I come up with) I obviously didn't express what I was getting at with my post above very well, so for that the group at large and the OP have my humblest appologies. I agree with Duffy's suggestion and would add the recommendation to use the value that uniquely identifies the object being stored as the key in the map to make finding it easier. The containsKey(...) method is a friend here.
Hope this helps,
PS.