【问题标题】:Retrieve ArrayLIst which is a value in HashMap [closed]检索作为 HashMap 中的值的 ArrayLIst [关闭]
【发布时间】:2013-06-28 07:11:30
【问题描述】:

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

【问题讨论】:

  • 呃,使用.get()... 为什么这个问题?
  • 您不能查看 HashMap 文档吗?
  • 使用.get()。是这个问题吗?
  • 这是一个技巧问题,对吧?

标签: java android arraylist hashmap bundle


【解决方案1】:

这里有一个完整的例子:

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
    }
}

【讨论】:

    【解决方案2】:

    你可以这样尝试

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

    【讨论】:

    • 密钥类型为Integer...
    猜你喜欢
    • 2014-10-20
    • 2013-11-01
    • 2023-04-08
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    相关资源
    最近更新 更多