[英]Java/Android - Search ArrayList<HashMap<String, String>> for matching key -> value
I have an ArrayList of HashMaps, and I have the key and value of one HashMap that I'd like to use to match the value of another HashMap found at a different position.. I have an ArrayList of HashMaps, and I have the key and value of one HashMap that I'd like to use to match the value of another HashMap found at a different position..
For example:例如:
1- [<key1, val1>, <key2, "some value">, <key3, val3>]
2- [<key1, val1>, <key2, val2>, <key3, val3>]
3- [<key1, "some value">, <key2, val2>, <key3, val3>]
And I know that Array.get(1).get(key2) == "some value"而且我知道 Array.get(1).get(key2) == "some value"
How can I then use this to match the key1 at Array.position(2), and return the value of key3?然后如何使用它来匹配 Array.position(2) 处的 key1,并返回 key3 的值?
Or in other words, how can I find the position of an ArrayList given the value of one of it's containing key/value HashMaps?或者换句话说,如果其中一个包含键/值哈希映射的值,我如何找到 ArrayList 的 position?
Something like Array.where("key1" == "some value").像 Array.where("key1" == "some value") 之类的东西。
Thanks谢谢
You have to do it brute-force way.你必须以蛮力的方式来做。
for(HashMap hm:HashMapArrayList)
if(hm.get(key1).equal(yourDesireValue)
{
//hm is the one you need to find out. Do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.