`
tanglei198577
  • 浏览: 57996 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

judgement method of collections

    博客分类:
  • java
阅读更多

When the collections want to evaluate the object is different from another object or not,it first to judge the mothod of hashcode() and equals()

		Set set = new HashSet();
		Integer a = new Integer(10);
		Integer b = new Integer(10);
		
		set.add(a);
		set.add(b);
		System.out.println(a==b);
		System.out.println(a.hashCode());
		System.out.println(a.hashCode()==b.hashCode());
		System.out.println(a.equals(b));
		System.out.println(set.size());

 

result is :

    false
    10
    true
    true
    1

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics