| Author |
need help with Collections
|
Nick Kocher
Greenhorn
Joined: Nov 24, 2004
Posts: 14
|
|
Hi, I need a method that would change the keys and values of the Properties instance so that keys become values and vice versa. I wrote my own version, but I think there must be already such a method somethere in Collections and I want to use it.
|
 |
Stefan Krompass
Ranch Hand
Joined: Apr 29, 2004
Posts: 75
|
|
Hi, there is no such method in the API since it would only work for a subset of all properties. Imagine the following case: When your values become keys, they are no longer unique. Stefan
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
Originally posted by Nick Kocher: I wrote my own version, but I think there must be already such a method somethere in Collections and I want to use it.
There is no such API method that I am aware of, for it's certainly an odd thing to do to a Map/Properties (not that it couldn't be useful). Also, it has the problem that Stefan mentioned. However, you can at least improve your method to iterate over the paired Map.Entry objects. I haven't looked at the Properties source, so I'm assuming it implements the Map interface. Finally, I recommend building a new Collection rather than modifying the one in-place.
|
 |
 |
|
|
subject: need help with Collections
|
|
|