Hash Collisions even after overriding equals and hashcode methods for object being stored as key in Hashmap
<p>I need to store object type of class edge as Key and ArrayList as Value</p>

<pre><code>public class edge {
    String edgeType;  // Horizontal or Vertical edge
    int i;            //i and j for a cell in 2D matrix
    int j;
}
HashMap&lt;edge, ArrayList&lt;String&gt;&gt; edgeHM = new HashMap&lt;edge, ArrayList&lt;String&gt;&gt;();
</code></pre>

<p>Each key's value Arraylist is initialized with 0 and 1</p>

<p>When I retrieve and edit one of the entries using the function <code>reduceEdgeDomain</code> multiple keys get updated with the value. Hash Collision?
Eg. need to update Key <code>H21</code>, keys updated <code>H21</code> and <code>V21</code> <code>(edgetype, i, j)</code></p>

<pre><code>H22 &lt;-&gt; V22 or V53 &lt;-&gt; H53

public static void reduceEdgeDomain(HashMap&lt;edge, ArrayList&lt;String&gt;&gt; edgeHM, ArrayList&lt;edge&gt; nonEssEdges){
        ArrayList&lt;String&gt; tempAL;
    for(int i=0; i&lt;nonEssEdges.size(); i++)
    {
        edge str = nonEssEdges.get(i);
        if(edgeHM.containsKey(str)){

            tempAL = edgeHM.get(str);
            edgeHM.remove(str);
            tempAL.remove("1");
            edgeHM.put(str, tempAL);

        }
    }
}
</code></pre>

<p>override methods for <code>equals()</code> and <code>hashcode()</code></p>

<pre><code>public boolean equals(Object o){
        if (this == o){
            return true;
        }

        if(!(o instanceof edge)){
            return false;
        }

        edge edge = (edge) o;
        return i==edge.i &amp;&amp; j==edge.j &amp;&amp; Objects.equals(edgeType, edge.edgeType);
    }

    @Override
    public int hashCode() {
        String uniqueIdentified = edgeType + i + j;
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        byte[] hash = digest.digest(uniqueIdentified.getBytes(StandardCharsets.UTF_8));
        ByteBuffer wrapped = ByteBuffer.wrap(hash); // big-endian by default
        short num = wrapped.getShort();
        return num;

    }
</code></pre>