| Author |
Is there a Properties-like class that allows multiple values per key?
|
Yuriy Zilbergleyt
Ranch Hand
Joined: Dec 13, 2004
Posts: 429
|
|
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
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
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
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Yuriy Zilbergleyt
Ranch Hand
Joined: Dec 13, 2004
Posts: 429
|
|
I think I'll try this. Thanks! -Yuriy
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
Or, if you can use Jakarta Commons Collections, there's a class called MultiHashMap in there that does exactly what you're asking for.
|
James Carman, President<br />Carman Consulting, Inc.
|
 |
 |
|
|
subject: Is there a Properties-like class that allows multiple values per key?
|
|
|