This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 18150
    
    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: 19552
    
  16

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: 19552
    
  16

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
 
Similar Threads
which map class is best for my need
Data structure for storing multiple elements for a unique key
sum of rows
appending parameters to url
Tree Map Question