2017-04-06 17 views
-3

我想實現一個包含hashmap<integer,ArrayList<integer>>Arraylist<integer>校驗值速滑運動員的肌肉的HashMap和ArrayList

我想測試中ArrayList的每一個值,如果它等於到ArrayList HashMap中值

例如第一個程序在HashMap中的第一元件與第二元件的第二數組列表元素數組列表元素散列映射等

如果是相等的餘incremete計數器並將其存儲在包含該密鑰和計數器

新散列映射

這是我做的

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

1.你沒有問一個問題,所以目前尚不清楚,你想知道什麼。 2.您的代碼將一個空數組列表與HashMap中包含的值進行比較。這聽起來不像你想要達到的。 3. HashMap條目的順序沒有實際含義。因此,將「第一元素」與任何事物進行比較都是沒有意義的 – Malt

+0

我不知道該怎麼做 如何用第一個hashmap元素測試第一個arraylist元素,用第二個元素測試第二個元素等 如果比較的元素是相同的,我會在計數器中加1,將計數器存儲在新的散列映射中 – fatoma

+0

HashMaps中的條目無序。術語「第一元素」沒有意義。 – Malt

回答

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++; 

    } 
0

HashMap不能維持秩序,你應該更喜歡使用LinkedHashMap的維持秩序,這樣就可以根據需要進行比較。

+0

如何使用LinkedHashMap? – fatoma

+0

@fatoma請參閱此鏈接http://stackoverflow.com/questions/6140856/what-is-linkedhashmapk-v – vijayraj34

+0

非常感謝你 – fatoma