查找HashMap是否包含所选值和返回键 [英] Find if HashMap contains chosen value and return key

查看:157
本文介绍了查找HashMap是否包含所选值和返回键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找到我的 HashMap< String,String> 是否包含值=x的条目(键,值)并按顺序遍历所有条目?

Is there any way to find if my HashMap<String, String> contains entry ( key,value) with value="x" and to go through all entries sequentially ?

推荐答案

HashMap.containsKey()

这个是什么 HashMap 首先是制作 ...

This is what HashMap is made for in the first place...

(不是确定你的意思是顺序完成所有条目。每个键只有1个条目。)

(Not sure what you mean by "to go through all entries sequentially", though. There's only 1 entry per key.)

编辑:

现在您编辑了问题,答案是! :(

Now that you edited the question, the answer is no! :(

如果你需要这个功能,设计你自己的双向 HashMap 来存储每个值的位置在另一个的值(希望是有意义的),然后使用该类。 HashMap s不是为此设计的。

If you need that feature, design your own two-way HashMap that stores the location of each value in the other's value (hopefully that made sense), and then use that class. HashMaps aren't designed for this.

这篇关于查找HashMap是否包含所选值和返回键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆