我要检查origMap的按键与otherMap。如果它发现从采取的othermap值作为origMap的键和值值用java低吞吐量
将其放入新的HashMap的HashMap的键比较。如果未找到,则使用Bigdecimal地点与关键字“other”中的Bigdecimal地点计算origmap的所有值,并将值设置为bigdecimal输出。我想下面,但它不工作投掷空指针,不知道是什么问题。
地图:
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");
代码:
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);
}
堆栈oveflow不允许添加代码,我正在尝试。 – user2684215
再努力尝试;) – Thomas
至于NullPointerException,请标记它出现的位置。 – Thomas