java HashMap containsKey is returning false though key is present
<p>I am using a HashMap data structure to store a SqMatrix (square matrix), where the key is of type MatrixIndex (which contains row and col) and the value is of type Integer. </p>

<p>But when I am getting false as output of "if (mat.containsKey(key))" though the HashMap has the corresponding key in it.</p>

<p>The main code: </p>

<pre><code>public static void main(String[] args) {

    Random generator = new Random();
    int val = 0;
    Types.MatrixIndex key, key1;
    int matSz = (int) Math.floor(Math.sqrt(10));
    Types.SqMatrix mat = new Types().new SqMatrix(matSz); //matSz*matSz elements
    //HashMap&lt;Types.MatrixIndex,Integer&gt; hMap= new HashMap&lt;Types.MatrixIndex,Integer&gt;(10);
    for (int r=0; r&lt;matSz; r++) {
        for (int c=0; c&lt;matSz; c++) {
            if (r&lt;c) {
                val = generator.nextInt(2) &gt; 0? -1 : val;
                key =(new Types()).new MatrixIndex(r, c);
                key1 = (new Types()).new MatrixIndex(c, r);
                mat.put(key, val);
                mat.put(key1, val);
                generator.setSeed(System.currentTimeMillis());
            }
        }
    }

    for (int r=0; r&lt;matSz; r++) {
        val = 0;
        for (int c=0; c&lt;matSz; c++) {
            if (r!=c) {
                key = (new Types()).new MatrixIndex(r, c);
                if (mat.containsKey(key)) {
                    val = val + mat.get(key);
                }

            }
        }
        key1 = (new Types()).new MatrixIndex(r, r);
        mat.put(key1, val);
    }
</code></pre>

<p>Do anybody have an idea on why the containsKey is returning false though it is present in the HashMap?</p>

<p>Thanks in advance,</p>

<p>Somnath</p>
