package com.test.collection;

import java.util.HashMap;
import java.util.Map; /**
* 重写equals & hashcode
*
* 1.如果两个对象的equals为true ,则hashCode也为true
* 2.重写equals时,必须重写hashCode(保证equals为true ,hashCode也为true)
* @author chenx
*
*/
public class Student { public Student(int id, String name) {
super();
this.id = id;
this.name = name;
} private int id;
private String name;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Student other = (Student) obj;
if (id != other.id)
return false;
return true;
}
}

最新文章

  1. 解决NetBeans运行web项目时出现的“未能正确设置java DB”问题
  2. android xml 布局错误
  3. 前端神器Sublime Text3 常用插件&常用快捷键
  4. 解析大型.NET ERP系统 代码的坏味道
  5. CSS里的pointer-events属性
  6. 如何启动/停止/重启MySQL
  7. 【读书笔记】读《JavaScript设计模式》之适配器模式
  8. javascript实例学习之五——瀑布流布局
  9. json字符串相关转换方法
  10. Net Core 的公共组件之 Http 请求客户端
  11. Codeforces Gym 100015F Fighting for Triangles 状压DP
  12. 栈中的push实现
  13. html5图片标签与属性
  14. DDD实践
  15. JavaScript用法
  16. 【做题】Codeforces Round #429 (Div. 2) E. On the Bench——组合问题+dp
  17. c#中快速排序的学习
  18. 汇编 inc 和 dec 指令
  19. bash里wget失败
  20. laravel 5.3 ——路由(资源,别名)

热门文章

  1. Windows NLB搭配IIS的ARR搭建高可用环境(转载)
  2. 获取一个表中的字段总数(mysql) Navicat如何导出Excel格式表结构 获取某个库中的一个表中的所有字段和数据类型
  3. α测试,Beta测试
  4. Java 简单的RPC 实现
  5. MySql 碎片
  6. rest-assured之静态导入及简单使用实例
  7. 自动生成缓存Key值的CacheKeyHelper
  8. vue 在使用v-html绑定的时候,里面的元素不会继承外部的css,解决方案
  9. [转] Java @interface 自定义注解
  10. JavaScript学习笔记2_面向对象