开发者

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..

For example:

1- [<k开发者_如何学Cey1, 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"

How can I then use this to match the key1 at Array.position(2), and return the value of 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?

Something like 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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜