import java.io.*;
import java.util.*;
class Experiment {
public static void main
(String args
[]) { Student s1 = new Student("uvw");
Student s2 = new Student("xyz");
HashSet<Student> set = new HashSet<>();
set.add(s1);
set.add(s2);
Student s3 = new Student("uvw");
System.
out.
println("s3 equals s1 ? " + s1.
equals(s3
)); System.
out.
println("s1 hash = " + s1.
hashCode()); System.
out.
println("s3 hash = " + s3.
hashCode());
System.
out.
println( set.
contains(s3
) ); }
}
class Student{
public Student
(String name
) {this.
name=name
;}
/* @Override
public int hashCode() {
return name.length();
}*/
@Override
public boolean equals
(Object obj
) { if (name.equals( ((Student)obj).name ))
return true;
return false;
}
@Override
return "Student{" +
"name='" + name + '\'' +
'}';
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgRXhwZXJpbWVudCB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcgYXJnc1tdKSB7CiAgICAgICAgU3R1ZGVudCBzMSA9IG5ldyBTdHVkZW50KCJ1dnciKTsKICAgICAgICBTdHVkZW50IHMyID0gbmV3IFN0dWRlbnQoInh5eiIpOwogICAgICAgIEhhc2hTZXQ8U3R1ZGVudD4gc2V0ID0gbmV3IEhhc2hTZXQ8PigpOwogICAgICAgIHNldC5hZGQoczEpOwogICAgICAgIHNldC5hZGQoczIpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihzZXQpOwogICAgICAgIAogICAgICAgIFN0dWRlbnQgczMgPSBuZXcgU3R1ZGVudCgidXZ3Iik7CiAgICAgICAgCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJzMyBlcXVhbHMgczEgPyAiICsgczEuZXF1YWxzKHMzKSk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJzMSBoYXNoID0gIiArIHMxLmhhc2hDb2RlKCkpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiczMgaGFzaCA9ICIgKyBzMy5oYXNoQ29kZSgpKTsKICAgICAgICAKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIHNldC5jb250YWlucyhzMykgKTsKICAgIH0KfQpjbGFzcyBTdHVkZW50ewoKICAgIFN0cmluZyBuYW1lOwoKICAgIHB1YmxpYyBTdHVkZW50KFN0cmluZyBuYW1lKSB7dGhpcy5uYW1lPW5hbWU7fQoKICAgLyogQE92ZXJyaWRlCiAgICBwdWJsaWMgaW50IGhhc2hDb2RlKCkgewogICAgICAgIHJldHVybiBuYW1lLmxlbmd0aCgpOwogICAgfSovCgogICAgQE92ZXJyaWRlCiAgICBwdWJsaWMgYm9vbGVhbiBlcXVhbHMoT2JqZWN0IG9iaikgewogICAgICAgIGlmIChuYW1lLmVxdWFscyggKChTdHVkZW50KW9iaikubmFtZSApKQoJcmV0dXJuIHRydWU7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQoKICAgIEBPdmVycmlkZQogICAgcHVibGljIFN0cmluZyB0b1N0cmluZygpIHsKICAgICAgICByZXR1cm4gIlN0dWRlbnR7IiArCiAgICAgICAgICAgICAgICAibmFtZT0nIiArIG5hbWUgKyAnXCcnICsKICAgICAgICAgICAgICAgICd9JzsKICAgIH0KfQ==