2013-07-01 44 views
-4

值我有一個HashMapHashMap<Integer, ArrayList<Bundle>> hashMap我能夠把值在HashMap。並且散列表被傳遞給下一個類。現在如何從HashMap得到BundleArrayList。任何我如何使用IteratorSet。但我仍然無法列出作爲數組列表的HashMap的值。這實際上是Message拾取器。我有多選模式使用回調listview。當我點擊一個短信列表,我需要得到一些細節,並將其存儲在hashmap。有可能短信可以有多個recepinets。 key將位置。我需要將HashMap的所有值爲ArrayList合併成一個單一的ArrayList。說int我們有[0,[A,B]],[1,[C,D]]的第0個位置,我想創建一個新的ArrayList並將A,B,C,D存儲在其中。檢索的ArrayList這是在HashMap中

+1

Uhwell,使用'獲得()'...爲什麼這個問題嗎? – fge

+2

不能你看看HashMap文檔? – Blackbelt

+0

使用'.get()'。這是個問題嗎? –

回答

1

你可以嘗試這樣的

ArrayList<Bundle> value = hashMap.get(yourkey); 
+0

鍵類型是整型... – jlordo

2

這裏有一個完整的例子:

public class Test { 
    private final String value; 

    public Test(String value) { 
     this.value = value; 
    } 

    public static void main(String[] args) { 
     HashMap<Integer, ArrayList<Test>> example = new HashMap<Integer, ArrayList<Test>>(); 

     ArrayList<Test> test1 = new ArrayList<Test>(); 
     test1.add(new Test("HELLO")); 

     ArrayList<Test> test2 = new ArrayList<Test>(); 
     test2.add(new Test("HELLO2")); 

     example.put(1, test1); 
     example.put(2, test2); 

     // We get the second arraylist 
     // Where 2 is the Integer we added in example.put(2, test2); 
     ArrayList<Test> testExtracted = example.get(2); 

     System.out.println(testExtracted.get(0).value); // Prints HELLO2 
    } 
}