I have an ArrayList which having many objects. I want to do sum of values of the same property name.
Examples Data in Array List which is Objects of ProfitAndLossDataDO
"Michel" , 5000
"Alex" , 5000
"Edvin" , 4000
"Sosha" , 3000
"Michel" , 2000
"Alex" , 3000
And the Result Would be (Sum of values when person are same)-
"Michel" ,7000
"Alex" , 8000
"Edvin" , 4000
"Sosha" , 3000
The Logic class ProfitAndLossDataDO
public class ProfitAndLossDataDO {
String ledgerName;
double ledgerAmount;
public ProfitAndLossDataDO() {
}
public ProfitAndLossDataDO(String ledgerName, double ledgerAmount) {
this.ledgerName = ledgerName;
this.ledgerAmount = ledgerAmount;
}
public String getLedgerName() {
return ledgerName;
}
public void setLedgerName(String ledgerName) {
this.ledgerName = ledgerName;
}
public double getLedgerAmount() {
return ledgerAmount;
}
public void setLedgerAmount(double ledgerAmount) {
this.ledgerAmount = ledgerAmount;
}
@Override
public String toString()
{
return ("ledger name : "+this.getLedgerName()+" Amount : "+this.getLedgerAmount());
}
}
Thanks