key: Hashcode Algorithm Hashcode
Alex A(1)+L(12)+E(5)+X(24) = 42
Dirk D(4)+I(9)+R(18)+K(11) = 42
This is an example from my text book. Both names with be found the the same bucket as their Hashcodes are the same, so to find the name you looking for you need to do an equality test.
They gave us an example of how to find the name you want using the equality test but i don't understand how it finds the name you want exactly.
Any help on this would be great!
Thanks
Alex A(1)+L(12)+E(5)+X(24) = 42
Dirk D(4)+I(9)+R(18)+K(11) = 42
This is an example from my text book. Both names with be found the the same bucket as their Hashcodes are the same, so to find the name you looking for you need to do an equality test.
They gave us an example of how to find the name you want using the equality test but i don't understand how it finds the name you want exactly.
public class HasHash { public static void main(String[] args) { } public int x; private int xValue; HasHash(int xVal) {x = xVal; } class x { private int xValue; x (int val) { xValue = val; } public int getxValue() { return xValue; } } public boolean equals(Object o) { HasHash h = (HasHash) o; if (h.x == this.x){ return true; }else{ return false; } } public int hashCode() { return (x * 17); } }
Any help on this would be great!
Thanks
