ArrayList<HashMap<String, Object>> list = ArrayList<HashMap<String, Object>>()
我有一个包含 HashMap 的数组列表,我能够获取 List 的位置,现在我如何获取 List 中对象的键 和
值。
@Override
public View getDropDownView() {
System.out.println(data.get(position)); // i am getting my List Objects
}
//下面是data.get(position)
的输出
{"title":"hello"}, => 0
{"title":"hello1"}, => 1
{"title":"hello2"}, => 2
{"title":"hello3"}, => 3
最佳答案
试试这个:
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
for (Map element : list) {
Set<Map.Entry<String, Object>> entrySet = element.entrySet();
for (Map.Entry<String, Object> mapEntry : entrySet) {
System.out.println("Key is : " + mapEntry.getKey());
System.out.println("Value is : " + mapEntry.getValue());
}
}
关于java - 检索 List 中 Map 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15633571/