小编use*_*466的帖子

谁在将元素放入HashMap时调用类的equals方法?

我是Java新手(非常新)。我试图了解HashMap和类的equals方法,以及它如何覆盖重复项。请参见以下代码:

public class Student {

    Integer StudentId;
    String Name;
    String City;

    public Student(Integer studentId, String name, String city) {
        super();
        StudentId = studentId;
        Name = name;
        City = city;
    }

    public Integer getStudentId() {
        return StudentId;
    }

    public String getName() {
        return Name;
    }

    public String getCity() {
        return City;
    }




    @Override
    public int hashCode() {
        System.out.println("haschode is called for " + this);

        final int prime = 31;
        int result = 1;
        result = prime * result + ((StudentId == …
Run Code Online (Sandbox Code Playgroud)

java hashmap java-8

6
推荐指数
4
解决办法
100
查看次数

标签 统计

hashmap ×1

java ×1

java-8 ×1