I want to check keys of origMap with otherMap .if it found take the value from othermap as key and value of origMap as value
place it into new hashmap. if not found calculate the all values of origmap using Bigdecimal place in the same map as key "other" and value as bigdecimal output. I am trying like below but it's not working throwing null pointer,not sure what is the issue.
Maps:
HashMap < String, Object > origMap = new HashMap < String, Object > ();
origMap.put("test", "1");
origMap.put("test2", "100.00");
origMap.put("test3", "3");
origMap.put("test4", "300.23");
HashMap < String, Object > otherMap = new HashMap < String, Object > ();
otherMap.put("test3", "fee");
otherMap.put("test2", "tax");
code:
Map newMap = new HashMap();
BigDecimal value1 = null;
for (Map.Entry <? , ?> me: origMap.entrySet())
{
String key = "";
String value = "";
if (otherMap.get(key).equals(me.getKey()))
{
key = otherMap.get(me.getKey()).toString();
value = origMap.get(me.getKey()).toString();
newMap.put(key, value);
}
else
{
value = origMap.get(me.getKey()).toString();
value1 = value1.add(new BigDecimal(value));
}
queryMap.put("others", value1);
}