Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Storing multiple values using a single key in Java 1.2  RSS feed

 
Drew Goldberg
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Drew Goldberg
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul and Rob for your help!


Cheers,

Drew
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!