一、hash方法
在进行add之前要知道hash方法对各种数据类型的操作规则
public class Test1 {
static final int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
public static void main(String[] args) {
//字符串类型对象
int hash = hash("tom");
System.out.println(hash);
hash = hash(new String("tom"));
System.out.println(hash);
//基本类型包装类对象
hash = hash(10000);
System.out.println(hash);
hash = hash(new Integer(10000));
System.out.println(hash);
//自定义类型对象
Student stu = new Student();
hash = hash(stu);
System.out.println(hash);
hash = hash(new Student