我想用相应的键遍历散列映射中的键和列表。
希望打印值(列表)。有人能帮上忙吗?
public class Demo {
public static void main(String[] args) {
HashMap<String,List<String> > hashmapobj = new HashMap<String,List<String>();
List<String> listobj=new ArrayList<String>();
listobj.add("yellow");
listobj.add("green");
listobj.add("orange");
listobj.add("blue");
hashmapobj.put("color", listobj);
hashmapobj.put("light", listobj);
}
}发布于 2016-09-19 01:28:37
for(Map.Entry<String, List<String>> items: hashmapobj.entrySet()){
System.out.print(items.getKey());
List<String> list = items.getValue();
for(String s : list){
System.out.print(" " + s);
}
System.out.println();
}这将打印您的key,然后将存储在List<String>中的所有值打印到同一行。每个key:value都有自己的一行。
https://stackoverflow.com/questions/39560414
复制相似问题