我有一个 ArrayList 作为 ArrayList<HashMap<String, String>> arrayList_LatLong = new ArrayList<HashMap<String, String>>();
我在其中将 HashMap 放入 ArrayList 中。 HashMap键值对假设如下
map.put(key1,value1);
map.put(key2,value2);
map.put(key3,value3);
map.put(key4,value4);
map.put(key5,value5);
现在我想要根据 Value1 的 ArrayList 索引,这意味着我有 Value1 并且我想要相应的 ArrayList 索引以便我也可以从相应的 HashMap 中获取其他值。
最佳答案
试试这个--->
public static int getIndexOFValue(String value, List<Map<String, String>> listMap) {
int i = 0;
for (Map<String, String> map : listMap) {
if (map.containsValue(value)) {
return i;
}
i++;
}
return -1;
}
关于java - 根据HashMap Key Value获取ArrayList Index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18653308/