How to swap keys and values in a Map elegantly

前端 未结 8 1867
滥情空心
滥情空心 2020-12-25 14:49

I already know how to do it the hard way and got it working - iterating over entries and swapping \"manually\". But i wonder if, like so many tasks, this one can be solved

8条回答
  •  春和景丽
    2020-12-25 15:05

    There are some jobs that can be simplified to a certain point and no more. This may be one of them!

    If you want to do the job using Java collections apis only then brute force is the way to go - it will be quick (unless the collection is huge) and it will be an obvious piece of code.

提交回复
热议问题