字符串列表ArrayList<String> strList1 存有
[a]
[b]
[c]
....字符串列表ArrayList<String> strList2 存有
[a,z1]
[a,z2]
[b,z1]
[b,z2]
[c,z1]
[c,z2]
....根据以上两个ArrayList对象变量我如何生成一个HashMap<String key,ArrayList list>对象变量
key:a  
value:
[a,z1]
[a,z2] 
...key:b  
value:
[b,z1]
[b,z2] 
...key:c  
value:
[c,z1]
[c,z2] 
...我描述的不是很好,但JAVA有经验的人应该明白我的意思吧。

解决方案 »

  1.   

    ArrayList<String> tempList = new ArrayList<String>();
    for(String a:linkedGlryshr){  
     hashMap = new HashMap<String,ArrayList<String>>();
     for(String b:toLeader){
       if(a.equals(b.split("@@@")[1])){           tempList.add(b.split("@@@")[1]+"@@@"+b.split("@@@")[2]);    
    }
        }  
    hashMap.put(a, tempList);
    }
      

  2.   

    Map map = new HashMap();
    for(int i = 0; i < strList1.size(); i ++){
      List tempList = new ArrayList();
      for(int j = 0; j < strList2.size(); j ++){
        String temp = (String)strList2.get(j);
        if(temp.split(",")[0].equals(strList1.get(i).toString())){
          tempList.add(temp);
        }
      }
      map.put(strList1.get(i).toString(), tempList);
    }