【问题标题】:How to iterate an ArrayList of HashMap如何迭代 HashMap 的 ArrayList
【发布时间】:2016-09-08 05:29:04
【问题描述】:

我有一个 hashmap 的数组列表。

ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String,String>>();

我想迭代那个。我正在这样做。

       Iterator it=al.iterator();
        while (it.hasNext()){

           it.remove(); 
                }

但我想在删除之前像这样比较。但它不起作用。我如何从 al 中获取价值?

if(al.get(it).get(db.name).equalsIgnoreCase(var)){

                         it.remove();       
                            }

【问题讨论】:

    标签: arraylist hashmap iterator


    【解决方案1】:

    要从迭代器中获取值,请使用it.next() 而不是al.get(it)

    HashMap<String, String> map = it.next();
    if (map.get(db.name).equalsIgnoreCase(var)) {
        it.remove();       
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 2012-03-07
      • 2021-07-31
      • 2017-06-12
      • 1970-01-01
      相关资源
      最近更新 更多