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.
Joined: Apr 29, 2004
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.
Joined: Aug 07, 2003
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.