Java 根据HashMap键值获取ArrayList索引
我有一个ArrayList作为Java 根据HashMap键值获取ArrayList索引,java,android,arraylist,hashmap,Java,Android,Arraylist,Hashmap,我有一个ArrayList作为ArrayList ArrayList\u LatLong=new ArrayList()中,我将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索引,这意味着
ArrayList ArrayList\u LatLong=new ArrayList()代码>中,我将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中获得其他值。我认为您只需要这样定义它:
ArrayList<HashMap<String, Integer>> arrayList_LatLong = new ArrayList<HashMap<String, Integer>>();
ArrayList ArrayList_LatLong=new ArrayList();
当您想在列表中获取索引时,您只需执行以下操作:
Integer newIndex = arrayList_LatLong.get(someIndex).get("aKey");
HashMap<String, Integer> indexes = arrayList_LatLong.get(newIndex);
Integer newIndex=arrayList_LatLong.get(someIndex.get(“aKey”);
HashMap index=arrayList_LatLong.get(newIndex);
我认为您只需要这样定义它:
ArrayList<HashMap<String, Integer>> arrayList_LatLong = new ArrayList<HashMap<String, Integer>>();
ArrayList ArrayList_LatLong=new ArrayList();
当您想在列表中获取索引时,您只需执行以下操作:
Integer newIndex = arrayList_LatLong.get(someIndex).get("aKey");
HashMap<String, Integer> indexes = arrayList_LatLong.get(newIndex);
Integer newIndex=arrayList_LatLong.get(someIndex.get(“aKey”);
HashMap index=arrayList_LatLong.get(newIndex);
试试这个-->
公共静态int-getIndexOFValue(字符串值,列表列表映射){
int i=0;
用于(映射:列表映射){
if(映射包含值(值)){
返回i;
}
i++;
}
返回-1;
}
试试这个-->
公共静态int-getIndexOFValue(字符串值,列表列表映射){
int i=0;
用于(映射:列表映射){
if(映射包含值(值)){
返回i;
}
i++;
}
返回-1;
}
您可以执行以下操作:
我在这里搜索“android”的值。您可以根据您的代码进行更改
String value = "android";
int getIndex(){
int i = -1;
for (Map<String, String> map : arrayList_LatLong) {
for (String key : map.keySet()) {
if (map.get(key).equals(value)) {
i = arrayList_LatLong.indexOf(map);
}
}
}
return i;
}
String value=“android”;
int getIndex(){
int i=-1;
用于(地图:arrayList_LatLong){
for(字符串键:map.keySet()){
if(map.get(key).equals(value)){
i=数组列表_LatLong.indexOf(map);
}
}
}
返回i;
}
您可以执行以下操作:
我在这里搜索“android”的值。您可以根据您的代码进行更改
String value = "android";
int getIndex(){
int i = -1;
for (Map<String, String> map : arrayList_LatLong) {
for (String key : map.keySet()) {
if (map.get(key).equals(value)) {
i = arrayList_LatLong.indexOf(map);
}
}
}
return i;
}
String value=“android”;
int getIndex(){
int i=-1;
用于(地图:arrayList_LatLong){
for(字符串键:map.keySet()){
if(map.get(key).equals(value)){
i=数组列表_LatLong.indexOf(map);
}
}
}
返回i;
}
公共静态int-getIndexOFkey(字符串键,ArrayList>listMap){
inti=0;
对于(i=0;ipublicstaticintgetindexofkey(字符串键,ArrayList>listMap){
inti=0;
例如(i=0;i用示例解释..用示例解释..如何缩进第一行并注释代码?如何缩进第一行并注释代码?