1.如果Map中没有重复的key,则会返回null,否则返回原始数据
package com.iterator.demo; import java.util.HashMap; import java.util.Map; public class IteratorDemo { public static void main(String[] args) { Map<String, Integer> map = new HashMap<String, Integer>(); map.put("", 1); map.put("two", 2); map.put(null, 3); System.out.println(map.put("two", 4));//key重复 System.out.println(map.put("five", 5)); } }
运行结果:
2
null