You need to sign in to do that
Don't have an account?
sfdcFanBoy
for loop a map
Hey All,
I have a map 'm' <String,Decimal> with Values
{
'abc',1000;
'xyz', 200;
'abc',100;
'qwe',600;
'qwe',800;
}
I need to add up the values if the key matches. So the map should be like below after processing the above map
Abc and qwe are repeating, for them the values should be added. (abc: 1000+100 and qwe: 600+800)
{
'abc',1100;
'xyz', 200;
'qwe',1400;
}
How to achieve this?
But I do not know what Keys it contains, so I cannot use static values like 'abc' directly in this --> if(M.containsKey('abc'))
We have to put a for loop and check for repeating Keys. How?
Ok here's the actual code.
String[] xNode = new String[]{};
Decimal[] yNode = new Decimal[]{};
//added few strings to xNode - 'abc','xyz','abc','qwe','qwe'
//added few decimals to yNode - 1000,200,100,600,800
for(i=0;i<xNode.size();i++){
m.put(xNode[i],yNode[i]);
}
Now how do I add the yNodes values if xNode is same. (abc,abc and qwe,qwe)
Hey
Go for this link
http://abhithetechknight.blogspot.in/2013/10/logic-for-maps-having-list-at-values.html
Hi,
Here is what you are looking for, if you are still looking...