ArrayList嵌套HashMap
下面展示一些 内联代码片
。
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
public static void main(String[] args) {
ArrayList<HashMap<String ,String>> ahmss = new ArrayList<HashMap<String,String>>();
HashMap<String,String> hmss1 = new HashMap<String,String>();
HashMap<String,String> hmss2 = new HashMap<String,String>();
HashMap<String,String> hmss3 = new HashMap<String,String>();
HashMap<String,String> hmss4 = new HashMap<String,String>();
hmss1.put("jsl","19");
hmss2.put("HuZhiYuan","19");
hmss3.put("KongMengQi","19");
hmss4.put("LiChengYang","19");
ahmss.add(hmss1);
ahmss.add(hmss2);
ahmss.add(hmss3);
ahmss.add(hmss4);
for(HashMap<String ,String> hm : ahmss){
Set<String> keySet = hm.keySet();
for(String key : keySet){
String s = hm.get(key);
System.out.println(key+" "+s);
}
}
}
HashMap嵌套ArrayList 3.30
下面展示一些 内联代码片
。
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Set;
public static void main(String[] args) {
HashMap<String,ArrayList<String>> hm = new HashMap<String,ArrayList<String>>();
ArrayList<String> arr1 = new ArrayList<String>();
arr1.add("爱睡觉");
arr1.add("爱打游戏");
arr1.add("喜欢吃了就睡");
hm.put("空",arr1);
ArrayList<String> arr2 = new ArrayList<String>();
arr2.add("爱学习");
arr2.add("爱踩点");
arr2.add("上课打游戏");
hm.put("远",arr2);
Set<String> hmsa = hm.keySet();
for(String s : hmsa){
System.out.print(s+" ");
ArrayList<String> arr = hm.get(s);
for(int i=0;i<arr.size();i++){
System.out.print(arr.get(i)+" ");
}
System.out.println();
}
}