【问题标题】:contains elements hashmap in arraylist java包含arraylist java中的元素hashmap
【发布时间】:2017-04-06 11:16:31
【问题描述】:

我有 hashmap<integer,arraylist<integer>> H 和 arraylist<integer> L 我想测试arraylist中的第一个元素是否与hashmap中的第一个值相似 这就是我想要的

 for (Entry<Integer, ArrayList<Integer>> e : hmm.entrySet()) {
        Integer key1 = e.getKey();

        List<Integer> valeur = e.getValue();
        int count = 0;
        int k = 0;
        //Integer temp : listOperateur;

        if (valeur.contains(listOperateur)) {
            count++;


        }

        sim.put(key1, count);
        k++;

    }

【问题讨论】:

    标签: java arraylist hashmap


    【解决方案1】:

    这段代码可以帮助你

        Iterator i1 = listOperateur.iterator();
        for (Map.Entry<Integer, ArrayList<Integer>> e : hmm.entrySet()) {
           //if (e.getValue() != null) {
                count = 0;
                //you can move this part to another method to avoid deep nested code
                for (Integer mapValue : e.getValue()) {
                    // for (Integer listValue : listOperateur) {
                    if (mapValue.equals(listOperateur.get(k))) {
                        count++;
                        //  }
                    }
                }
                sim.put(e.getKey(), count);
                k++;
          //  }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2014-01-22
      • 2012-01-01
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      相关资源
      最近更新 更多