私のプログラムは正常に動作していますが、結果は間違っています。私はHashMap<Integer, ArrayList<Integer>>
とArrayList<Integer>
を使用し、私のプログラムは新しいHashMap<integer, ArrayList<Integer>>
を生成します。プログラムはHashMap
の各値とArrayList
の値を比較し、同様の値を追加して結果を新しいHashMap
に格納する必要があります。あなたの理解を深めるための写真を追加しました。hashmapとarraylistの値が類似しています
例:
ArrayList<Integer> :
[1, 0, 1, 0, 0]
Hashmap<Integer,ArrayList<integer>> :
1, [1, 0, 1, 1, 0]
2, [0, 1, 1, 0, 0]
3, [0, 1, 1, 1, 0]
結果:
HashMap
1, 4
2, 3
3, 2
コード:
System.out.println("HASHMAP SIMILIRATE RESULT:");
HashMap<Integer, Integer> sim = new HashMap<Integer, Integer>();
int count;
int k = 1;
for (Map.Entry<Integer, ArrayList<Integer>> e : hmm.entrySet()) {
count = 0;
//you can move this part to another method to avoid deep nested code
for (Integer mapValue : e.getValue()) {
if (mapValue.equals(listOperateur.get(k))) {
count = count + 1;
}
}
sim.put(e.getKey(), count);
k++;
}
あなたのコードを投稿してください。 – stinepike
@StinePike 投稿したことは申し訳ございません – fatoma
今日は早くOPを手伝ってみましたが、コードはあまりにも厄介で、彼の問題はちょっと意味がありません。 –