• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is there a Properties-like class that allows multiple values per key?

 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello fello Java folk,

I know this would be really simple to implement, but I'm wondering if a standard implementation already exists. I'm looking for a class like Properties, but which maps a list of string values to a string key. Sort of like the way ServletRequest handles parameters, but with ability to add and remove new ones. I need the methods getPropertyValues(key), addPropertyValue(key, value) and removePropertyValue(key, value). When the last value of a key is removed, the key itself is removed from the collection.

I'm only going to be using this with Strings, but if an implementation exists only for Objects, casting will not present a problem.

Thank you in advance,
Yuriy
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could write one with a Map of Sets.

Does that make enough sense to figure out get and remove? Then you could make a class that loads and saves as text or XML. Could be kinda fun
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I'll try this. Thanks!

-Yuriy
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or, if you can use Jakarta Commons Collections, there's a class called MultiHashMap in there that does exactly what you're asking for.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic