我想要实现一个包含hashmap<integer,ArrayList<integer>>
和Arraylist<integer>
我想测试arraylist中的每个值,如果它等于arraylist hashmap值
例如,第一个arraylist元素包含hashmap中的第一个元素,第二个arraylist元素包含第二个元素hashmap等。
如果相等,我会增加计数器并将其存储在包含密钥和计数器的新哈希图中
这就是我做的事情
HashMap<Integer, Integer> sim = new HashMap<Integer, Integer>();
List<Integer> listOperateur = new ArrayList<Integer>();
for (Map.Entry<Integer, ArrayList<Integer>> e : hmm.entrySet()) {
//hmm and listOperateur Already established and filled
if (e.getValue().equals(listOperateur)) {
count++;
}
sim.put(e.getKey(), count);
}
}
答案 0 :(得分:0)
Hashmap不维护订单,您应该更喜欢使用 LinkedHashMap 来维护订单,以便您可以根据需要进行比较。
答案 1 :(得分:0)
我做了这个程序,做了我需要的但它没有给出正确的结果
Iterator i1 = listOperateur.iterator();
for (Map.Entry<Integer, ArrayList<Integer>> e : hmm.entrySet()) {
count = 0;
for (Integer mapValue : e.getValue()) {
if (mapValue.equals(listOperateur.get(k))) {
count++;
}
}
sim.put(e.getKey(), count);
k++;
}