求高手:如果把一个ArrayList放进HashMap,如何从HashMap里面把ArrayList的具体值取出来用。最好能写个具体的例子非常谢谢
1 回答
Its_forever
TA贡献361条经验 获得超328个赞
public class ArrayListInHashMap {
public static void main(String[] args) {
ArrayList<Integer> arrayList = new ArrayList<Integer>();
HashMap<Integer,ArrayList<Integer>> hashMap = new HashMap<Integer,ArrayList<Integer>>();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
arrayList.add(5);
hashMap.put(1, arrayList);
Iterator<Integer> it = hashMap.keySet().iterator();
Integer next = it.next();
ArrayList<Integer> arrayList2 = hashMap.get(next);
for (Integer integer : arrayList2) {
System.out.println(integer);
}
}
}不知道是不是你想要的。
添加回答
举报
0/150
提交
取消
