Map 如何在具有顶点的贴图中增加值?

Map 如何在具有顶点的贴图中增加值?,map,salesforce,apex-code,increment,visualforce,Map,Salesforce,Apex Code,Increment,Visualforce,有没有一种方法可以在不需要第二个变量的情况下增加映射中的值 例如,这不起作用: counts = new Map<string,integer>(); counts.put('month_total',0); counts.put('month_total',counts.get['month_total']++); counts=newmap(); 计数。卖出价('月份合计',0); counts.put('month_total',counts.get['month_total

有没有一种方法可以在不需要第二个变量的情况下增加映射中的值

例如,这不起作用:

counts = new Map<string,integer>();
counts.put('month_total',0);
counts.put('month_total',counts.get['month_total']++);
counts=newmap();
计数。卖出价('月份合计',0);
counts.put('month_total',counts.get['month_total']+);
它返回“字段表达式的初始项必须是具体的SObject:MAP”

相反,我需要做:

counts = new Map<string,integer>();
counts.put('month_total',0);
integer temp = 0;
temp++;
counts.put('month_total',temp);
counts=newmap();
计数。卖出价('月份合计',0);
整数温度=0;
temp++;
计数。put('月份总数',温度);
是否有任何方法可以在不需要额外变量的情况下递增?

替换

counts.put('month_total',counts.get['month_total']++);

List lststrings=新列表{'key','wewewe','sdsd','key','dfdfd','wewewe'};
Map mapval=新映射();
整数计数=1;
用于(字符串str:lststrings){
IF(mapval.containsKey(str)){
mapval.put(str,mapval.get(str)+1);
}
否则{
mapval.put(str,count);
}
}
system.debug('mapval'的值+mapval);

非常感谢,修复了它。但是我确实需要将它从
++
更改为
+1
,因为我得到了一个“表达式不能赋值”错误。也许在你的回答中更新一下?
counts.put('month_total',counts.get('month_total')++);
List<String> lststrings = new List<String>{'key','wewe','sdsd','key','dfdfd','wewe'};
    Map<String,Integer> mapval = new Map<String,Integer>();
Integer count = 1;
for(string str : lststrings){
    IF(mapval.containsKey(str)){
        mapval.put(str,mapval.get(str)+1);
    }
    else{
        mapval.put(str,count);
    }
}
system.debug('value of mapval'+mapval);