查找HashMap是否包含所选值和返回键 [英] Find if HashMap contains chosen value and return key
问题描述
有没有办法找到我的 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
首先是制作 ...
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. HashMap
s aren't designed for this.
这篇关于查找HashMap是否包含所选值和返回键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!