码迷,mamicode.com
首页 > 其他好文 > 详细

hashcode的一些了解

时间:2016-12-14 18:50:32      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:string   str   内存   字符串类型   rgs   log   static   算法   不同   

1.hashcode的作用?

  hashcode代表对象的特征,在集合类中广泛的使用。

2.hashcode是如何生成的?

  在普通的对象中,获得对象的内存的地址,经过一些算法,不同对象生成不同的hashcode

  字符串类型,它会根据字符串的内容,生成相关的hashcode

  

public class Test1 {
    public static void main(String args[]){
        
        String c = "ac";
        String d = "ab";
        System.out.println(c.hashCode()+"||"+d.hashCode());
    }
}//结果:3106||3105

  Integer类型,返回数字本身为hashcode,注意:hashcode()返回值就是integer

hashcode的一些了解

标签:string   str   内存   字符串类型   rgs   log   static   算法   不同   

原文地址:http://www.cnblogs.com/bingscode/p/6180248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!