求高手:如果把一個ArrayList放進HashMap,如何從HashMap里面把ArrayList的具體值取出來用。最好能寫個具體的例子非常謝謝
1 回答
Its_forever
TA貢獻361條經(jīng)驗 獲得超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
提交
取消
