看JDK说明 Set<K> keySet() 
          Returns a Set view of the keys contained in this map. Collection<V> values() 
          Returns a Collection view of the values contained in this map. 返回类型,直接说明问题,返回键集合是set,返回值集合是Collection(很明显JDK意思是:不排除重复)

解决方案 »

  1.   

    就像函数关系:y=f(x)一样,(x,y)关系,x是不可以重复的键,y是有可能重复的。
      

  2.   

    Map 要求 key 的值是一个不变的对象, 像 String, Integer 之类,
      

  3.   

    value随便  key也不能说不允许重复  只是重复了覆盖而已
      

  4.   

    键 是可以重复的 但是值不可以重复map 就是这么规定的
      

  5.   

    键是set 值是collection 当然可以重写啦
    package yingxi.yingkeyuan2;import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;public class HashMapTest
    {
    public static void main(String[] args) {
    HashMap map = new HashMap();
    for(int i=0;i<args.length;i++)
    {
    if(map.get(args[i])==null)
    {
    map.put(args[i],new Integer(1));
    }
    else
    {
    Integer in =(Integer)map.get(args[i]);
    in = new Integer(in.intValue()+1);
    map.put(args[i],in);
    }
    Set set = map.keySet();
    for(Iterator it =set.iterator();it.hasNext();)
    {
    String key = (String)it.next();
    Integer value =(Integer)map.get(key);
    System.out.println(key+" : "+value);
    }
    }
    }}
      

  6.   


    看JDK说明 Set<K> keySet() 
              Returns a Set view of the keys contained in this map. Collection<V> values() 
              Returns a Collection view of the values contained in this map. 返回类型,直接说明问题,返回键集合是set,返回值集合是Collection(很明显JDK意思是:不排除重复)
    好解释
      

  7.   

    这个问题 你也来问,你试一试啊,了解一下Map 的数据结构。
      

  8.   

    key 不能重复 后put的key-value 会覆盖之前已经put的
      

  9.   

    值是可以重复的。
    Set<E> 是不能重复的 
    List<E>是可以重复的.
      

  10.   

    可以重复,不过 如果key相等, 那么key值将被覆盖,取代先前的key,value随之改变,如果key不等,那么将开辟新的内存空间,来存储key-value的值,此时 先前的key和后者key ,他们的存储地址是不同的.
      

  11.   

    key和value都是可以重复的,也可以为null
      

  12.   

     public static void main(String[] args) {
    HashMap<Integer,String> map=new HashMap<Integer,String>();
    map.put(1, "apple");
    map.put(1, "pear");
    map.put(2, "cars");
    for(Integer a: map.keySet()){
        System.out.println(a+"   "+map.get(a));
        
    }1   pear
    2   cars