能否举例?
没碰到过此类情况,觉得有些抽象。

解决方案 »

  1.   

    HashMap?
    这个是map啊
    一个键值对应一个数据
    键值肯定是唯一的啦楼主想问的是HashSet吧?
      

  2.   

    当然可能Long l = new Long(1);
    Long ll = new Long(1l << 32);
    System.out.println(l.hashCode());
    System.out.println(ll.hashCode());都是1
      

  3.   

    System.out.println("Aa".hashCode());
    System.out.println("BB".hashCode());
      

  4.   

    其实有个最简单的例子
    两个String
    hashCode()一样
    equals不一样 String aString = "Aa";
    String bString = "BB";
    System.out.println(aString.hashCode());
    System.out.println(bString.hashCode());
    System.out.println(bString.equals(aString));
      

  5.   

    在一般对象的equals方法里,用hashcode来判断是否是同一个对象。但是String的equals方法是被重写的,只要字符串值一样就为true了。
      

  6.   

    大家都举过例了,像这种理论是上被强调过的It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results.有要求说equal的两个对象hashcode要相同,但没有要求不equal的两个对象hashcode一定不同hashcode是这样算的吧
    s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]s数组是string的char数组,n是string长度,这个算式能证明些问题吧
      

  7.   

    HashMap<String,Integer> hm=new HashMap<String,Integer>();
    hm.put("Aa",123);
    hm.put("BB",12);
    存入"Aa",123 键值对后
    再次存入"BB",12 键值对时,
     int i = indexFor(hash, table.length);
    for (Entry<K,V> e = table[i]; e != null; e = e.next) {
                Object k;
                if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
                    V oldValue = e.value;
                    e.value = value;
                    e.recordAccess(this);
                    return oldValue;
                }
            }
            modCount++;
            addEntry(hash, key, value, i);
            return null;e.hash == hash 比较下来相等 但是((k = e.key) == key 不相等 故值不覆盖
    但是它们存入的位置都相同。暂时没问题了 ,但后面肯定还有问题,
    所以抱歉,先不结帖了 。