在学map集合,遇到了问题,这两段代码为什么输出结果会不一样呢,get()方法后面的 “” “” 是有什么意义吗?
public class CollectionDemo10_4 {
public static void main(String[] args) {
Map<String, String> map = new HashMap<String,String>();
//创建map集合
map.put("1","apple");
map.put("2", "pear");
map.put("3", "orange");
//向集合中添加对象
for(int i = 1;i <= 3;i++) {
System.out.println("第" + i + "元素是:" + map.get("" + i + ""));
}
}
}
输出结果:
第1元素是:apple
第2元素是:pear
第3元素是:orange
public class CollectionDemo10_4 {
public static void main(String[] args) {
Map<String, String> map = new HashMap<String,String>();
//创建map集合
map.put("1","apple");
map.put("2", "pear");
map.put("3", "orange");
//向集合中添加对象
for(int i = 1;i <= 3;i++) {
System.out.println("第" + i + "元素是:" + map.get(i));
}
}
}
输出结果:
第1元素是:null
第2元素是:null
第3元素是:null