-5

我有一个HashMap HashMap<Integer, ArrayList<Bundle>> hashMap我能够将值放入HashMap. 并且 hashmap 被传递给下一个类。现在如何ArrayListBundle . HashMap任何我如何使用Iterator Set. 我仍然无法列出作为数组列表的 HashMap 的值。这实际上是消息选择器。而且我有使用回调列表视图的多选模式。当我单击一个短信列表时,我需要获取一些详细信息并将其存储在一个hashmap. 一条短信可能有多个接收器。将key是位置。我需要将HashMapthat is的所有值ArrayList合并到一个ArrayList. 假设我们有 [0,[A,B]] ,[1,[C,D]] 的第 0 个位置,我想创建一个新的数组列表并在其中存储 A 、 B 、 C 、 D 。

4

2 回答 2

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
    }
}
于 2013-07-01T08:09:29.907 回答
1

你可以这样尝试

ArrayList<Bundle> value = hashMap.get(yourkey);
于 2013-07-01T08:06:19.030 回答