Reputation: 923
I have two hashmaps. Each of those have keys as other hashmaps like the one below.
Map<Map<String, Object>, Map<String, Object>>
This map gets filled from values of a DB2 database query output. I have noticed that even when I have two such hashmaps and if I try to retrieve the value for a hashmap key, it always returns me null. I have checked by adding all the needed variables in watch window. Everything looks good to me.
Small snippet of my code.
mapTransactionNumberTranIds
.put(inputMessageDbRecord
.get(i)
.get(prop.getProperty(
BloombergConstants.INPUT_BBR_TRANS_NO).toString())
.toString(),
inputMessageDbRecord
.get(i)
.get(prop.getProperty(
BloombergConstants.TRAN_ID)
.toString()).toString());
Note:
inputMessageDbRecord is of type List<Map<String, Object>>
and mapTransactionNumberTranIds is of type Map<Map<String, Object>, Map<String, Object>>
Upvotes: 0
Views: 202
Reputation: 827
You also have to understand that the key will only work if you have the exact same object instance for adding and retrieving from the map and the key is not allowed to never change, because comparison will check if the key is the same instance using equals() and hashCode().
This article describes issues about using object as key in a hashmap.
Most likely, the problem you are facing is related to those requirements.
Upvotes: 2