import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/*public class hashmap {
*//**
* @param args
*//*
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String, ArrayList<Integer>>hash=new HashMap<String, ArrayList<Integer>>();
String key="aa";
hash.put(key, hash.get(key));
//hash.get("aa").add(22);
System.out.println(hash.get(key).add(2));
}
}*/
public class Test {
public static ArrayList<String> listA=new ArrayList<String>();
public static ArrayList<String> listB=new ArrayList<String>();
public static HashMap<Integer,ArrayList<String>> hashmapA=new HashMap<Integer,ArrayList<String>>();
public static HashMap<Integer,ArrayList<String>> hashmapB=new HashMap<Integer,ArrayList<String>>();
public static void main(String args[]) {
listA.add("AAA");
listA.add("aaa");
listA.add("AAAAA");
listA.add("bbbb");
listA.add("kkkkk");
listB.add("OOOO");
listB.add("llll");
listB.add("pppp");
listB.add("ppppp");
listB.add("nnnn");
hashmapA.put(1, listA);
hashmapA.put(2, listB);
System.out.println(hashmapA);
for(Iterator i = hashmapA.keySet().iterator();i.hasNext();)
{
Integer interger = (Integer)i.next();
List<String> list = hashmapA.get(interger);
for(String s: list)
{
System.out.println(s);
}
}
}
}
输出结果为
{1=[AAA, aaa, AAAAA, bbbb, kkkkk], 2=[OOOO, llll, pppp, ppppp, nnnn]}
AAA
aaa
AAAAA
bbbb
kkkkk
OOOO
llll
pppp
ppppp
nnnn
{1=[AAA, aaa, AAAAA, bbbb, kkkkk], 2=[OOOO, llll, pppp, ppppp, nnnn]}
AAA
aaa
AAAAA
bbbb
kkkkk
OOOO
llll
pppp
ppppp
nnnn
{1=[AAA, aaa, AAAAA, bbbb, kkkkk], 2=[OOOO, llll, pppp, ppppp, nnnn]}
AAA
aaa
AAAAA
bbbb
kkkkk
OOOO
llll
pppp
ppppp
nnnn