每个string 都有自己的hashcode,这个方法可以用来区别字符串,以及获得或者读出字符用的。我经常这么用。比方说String s="fishstudio";
s.hashcode();就可以得到相应的hash码了
可能有别的用法,我就知道这么多

解决方案 »

  1.   

    这个方法是计算该对象的散列值,在Hashtable,HashMap这类使用散列值的地方用得着,如果使用容器,建立实例池,最常见的比如自己的entityBean primaryKey Class也用的着。
    一般来说a.equal(b)==true => a.hashcode()==b.hashcode(),反之则未必。但是如果a.equal(b)==true <=> a.hashcode()==b.hashcode()推论成立则会大大提高效率!如:
    String s1="BF"; //hashcode= 'B'*31+'F'
    String s2="Ae"; //hashcode= 'A'*31+'e'
    Both have hashcode of 2116.
      

  2.   

    hashcode是为生成HashSet或者HashMap等标准库类的
    这些类会自动调用所要存储的对象的hashcode得到一个整数,以确定应该把这个对象存储在类中的什么位置。建议看看Thinking in Java 2nd
      

  3.   

    为支持集合类的,
    如楼上所说的HashMap等,HashMap等就是依hashcode生成的不同值来辨别它所存的对象的