File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Storing multiple values using a single key in Java 1.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Storing multiple values using a single key in Java 1.2" Watch "Storing multiple values using a single key in Java 1.2" New topic
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: 18564
    
    8

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: 19692
    
  20

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 - OCEEJBD 6
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: 19692
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing multiple values using a single key in Java 1.2