HashMap.containsValue - What's the point?

前端 未结 7 749
臣服心动
臣服心动 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:53

    Let me reframe this question for Frederik:

    Well, containsValue(), does it compare internally (its input parameter) with every "value" in the hashmap? Or does it uses somehow hashcodeing (or other technique) to generate the result? For the former case, we could simply use an iterator to traverse and match the existence of our value with all the hashmap's "value". The significance of the question is in the performance, or speed!

提交回复
热议问题