| Author |
Storing multiple values using a single key in Java 1.2
|
Drew Goldberg
Greenhorn
Joined: Sep 11, 2011
Posts: 12
|
|
Hello,
I was wondering if there is a way to store multiple values for a single key in java 1.2, which I believe means no Generics?
Cheers,
Drew
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
Sure. The usual way is to have the key mapped to a list of values.
(I don't know what Generics has to do with the question... could you expand on that?)
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Generics aren't an issue here. In all Java versions the way to go with the existing API is to use a Map with a collection (list, set) as its values.
If you want an easier interface, check out Apache Commons Collections or Google Guava - both have a multi map. However, Google Guava isn't an option for you as it's written using generics, and needs to be heavily modified to get working in Java 1.2. You should theoretically be able to recompile Apache Commons Collections using a Java 1.2 compiler, as it doesn't use generics (yet).
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Drew Goldberg
Greenhorn
Joined: Sep 11, 2011
Posts: 12
|
|
Thanks Paul and Rob for your help!
Cheers,
Drew
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You're welcome.
|
 |
 |
|
|
subject: Storing multiple values using a single key in Java 1.2
|
|
|