初始化map,返回map
public static Map<String, String[]> newStadiumFieldList () {
Map<String, String[]> map = new HashMap<>();
map.put("羽毛球", new String[]{"羽毛球场地1", "羽毛球场地2", "羽毛球场地3", "羽毛球场地4", "羽毛球场地5"});
map.put("乒乓球", new String[]{"乒乓球场地1", "乒乓球场地2", "乒乓球场地3", "乒乓球场地4"});
map.put("篮球", new String[]{"篮球场地1", "篮球场地2", "篮球场地3"});
return map;
}
遍历输出键值对
public static void getStadiumField(Map<String, String[]> map){
System.out.println("集合大小:"+map.size());
map.forEach((key,value)->{
System.out.println("key:"+key+"; value:"+value);
});
}
输出的是内存地址,用toString好像也是内存地址
应该输出后面的球场123456的
public static void getStadiumField(Map<String, String[]> map){
System.out.println("集合大小:"+map.size());
map.forEach((key,value)->{
System.out.println("key:"+key+"; value:"+value[0]);
});
}
public static void getStadiumField(Map<String, String[]> map) {
System.out.println("集合大小:" + map.size());
map.forEach((key, value) -> {
for (String s : value) {
System.out.println("key:" + key + "; value:" + s);
}
});
}
value是数组,所以还要遍历一遍
println打印时 默认就是对象.toString()拼接的
如果能帮到你,望【采纳】谢啦