Basic HashMap
We need to implement equals and hashCode when we create new class as a hash key
public static class SampleClass {
public int i;
public int j;
public SampleClass(int i, int j) {
this.i = i;
this.j = j;
}
@Override
public boolean equals(Object o) {
if(this == o) {
return true;
}
if(o == null || getClass() != o.getClass()) {
return false;
}
SampleClass smpl = (SampleClass)o;
return i == smpl.i && j == smpl.j;
}
@Override
public int hashCode() {
return i * 10 + j;
}
}