求高手:如果把一個(gè)ArrayList放進(jìn)HashMap,如何從HashMap里面把ArrayList的具體值取出來(lái)用。最好能寫(xiě)個(gè)具體的例子非常謝謝
1 回答

Its_forever
TA貢獻(xiàn)361條經(jīng)驗(yàn) 獲得超328個(gè)贊
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); } } }
不知道是不是你想要的。
添加回答
舉報(bào)
0/150
提交
取消