Hashmap cotainskey 结果有问题

package Hashmap;

import java.util.*;

public class HashMapDemo {
public static void main(String args[]) {
// create hash map
HashMap> TT = new HashMap<>();
ArrayList gIds = null;
Test t1=new Test(0, 1, 0, 0, 0);
Test t2=new Test(0, 1, 0, 0, 0);
TT.put(t1, gIds);

   if (!TT.containsKey(t2)) {
        System.out.println("不含");
    } else {
        gIds = TT.get(t2);
        System.out.println("找到");
    }

}

}
class Test{
public int a;
public int b;
public int c;
public int d;
public int e;
public Test(int a,int b,int c,int d,int e){
this.a=a;
this.b=b;
this.c=c;
this.d=d;
this.e=e;
}
}

输出的结果是不含,请问为什么,我该怎么改呢?

需要重写equals,否则比较的是引用,不是你的属性。

需要,因为你的Key是Test类型的。