Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to make a java lex analyzer 
Java :: how to add 0 in left padding using regular expression java 
Java :: why fields should be final in immutable class? 
Java :: UIManager.setLookAndFeel Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke because "style" is null 
Java :: action media scanner scan file android 30 deprecated 
Java :: how to make a string alphabetic 
Java :: How to convert Javascript return value to String in Android 
Java :: arrays in constructor java 
Java :: https://www.baeldung.com/java-stream-findfirst-vs-findany 
Java :: the built-in base class in java, which is used to handle all exceptions is 
Java :: Filter out any non-printable characters 
Java :: java multi threading Buzzer program 
Java :: how to put comments on swagger documentation in spring boot 
Java :: write a code to print second last word of input string 
Java :: Display a Text Five Times 
Java :: Java @Repeatable 
Java :: private void loadmaze(string mazefile) 
Java :: javalin pom 
Java :: labelled for loop in java 
Java :: last resultset method 
Java :: public class MyClass { public static void main(String[] args) { System.out.println("Hello World"); } } 
Java :: handle customized popup in selenium 
Java :: how to convert a jsonobject to a dbobject 
Java :: what is the use of the tolowercase in java 
Java :: what does the continue keyword do in java 
Java :: java producer consumer queue 
Java :: Use following code to open activity while your application is not running. 
Java :: how to set id to TextView programmatically java android 
Java :: Repeat execution of function infini android studio 
Java :: call to jdbc template each class not by super 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =