java - 检索 List 中 Map 的值

标签 java

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/

相关文章:

java - 是否需要我的 try catch block ?

java - Springsource Tool Suite导入Spring3.0的jpetstore时maven报错

Java二叉树: Finding the node that reaches two nodes with shortest distance

java - 网络服务 :Understanding the task assigned

java - 在哪里可以找到为 GroupLayout 构建组的工具?

java-使用提交事务插入表

java - 阔叶 UTF-8 编码

FileChooser 保存对话框上的 JavaFX ExtensionFilter 在 macOS 上太宽

java - JUnit测试编译

java - 没有提交 Ignite CacheStoreAdapter