HashMap.containsValue - What's the point?

前端 未结 7 810
臣服心动
臣服心动 2021-01-04 13:16

I\'ve got a HashMap and I need to fetch an item by its integer value. I notice there\'s a containsValue() function, but it would appear I still have to iterate through the m

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 13:52

    you can use containsValue() in cases where you don't need to traverse the whole hashmap, for example if you want to add key-value pair to hashmap, but before that you want to know if that value is in hashmap. In this case for add operation you don't need to traverse whole hashmap.

提交回复
热议问题