我有一个包含许多对象的ArrayList.我想对相同属性名称的值进行求和.
示例数组列表中的数据,它是ProfitAndLossDataDO的对象
"Michel" , 5000
"Alex" , 5000
"Edvin" , 4000
"Sosha" , 3000
"Michel" , 2000
"Alex" , 3000
结果将是(人相同时的值总和)-
"Michel" ,7000
"Alex" , 8000
"Edvin" , 4000
"Sosha" , 3000
逻辑类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());
}
}
谢谢