Horje
Designing a HashMap Key Code Example
Designing a HashMap Key
public class Coordinate {
    private final int x;
    private final int y;
    private int hashCode;

    public Coordinate(int x, int y) {
        this.x = x;
        this.y = y;
        this.hashCode = Objects.hash(x, y);
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Coordinate that = (Coordinate) o;
        return x == that.x && y == that.y;
    }

    @Override
    public int hashCode() {
        return this.hashCode;
    }
}




Java

Related
how to change default port in spring boot Code Example how to change default port in spring boot Code Example
Uri/Beecrowd problem no - 1150 solution in Java Code Example Uri/Beecrowd problem no - 1150 solution in Java Code Example
tostring java Code Example tostring java Code Example
java parse date with optional timezone Code Example java parse date with optional timezone Code Example
using condition for each loop Code Example using condition for each loop Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10