检索的ArrayList这是在HashMap中
问题描述:
值我有一个HashMap
HashMap<Integer, ArrayList<Bundle>> hashMap
我能够把值在HashMap
。并且散列表被传递给下一个类。现在如何从HashMap
得到Bundle
的ArrayList
。任何我如何使用Iterator
Set
。但我仍然无法列出作为数组列表的HashMap的值。这实际上是Message拾取器。我有多选模式使用回调listview。当我点击一个短信列表,我需要得到一些细节,并将其存储在hashmap
。有可能短信可以有多个recepinets。 key
将位置。我需要将HashMap
的所有值为ArrayList
合并成一个单一的ArrayList
。说int我们有[0,[A,B]],[1,[C,D]]的第0个位置,我想创建一个新的ArrayList并将A,B,C,D存储在其中。检索的ArrayList这是在HashMap中
答
这里有一个完整的例子:
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
}
}
Uhwell,使用'获得()'...为什么这个问题吗? – fge
不能你看看HashMap文档? – Blackbelt
使用'.get()'。这是个问题吗? –