概述
需求:两个list内object数据进项相加,获得新的数据,以下是我的代码部分:
List<MoneyCountBean> counttradeamt = commonService.getList("counttradeamt", bean);
List<MoneyCountBean> countrefundamt = commonService.getList("countrefundamt", bean);
List<JSONObject> jsonList = new ArrayList<JSONObject>();
for (MoneyCountBean tradeamt : counttradeamt) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", tradeamt.getId());
jsonObject.put("count", tradeamt.getCounttradeamt());
jsonList.add(jsonObject);
}
for (MoneyCountBean fundamt : countrefundamt) {
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("id", fundamt.getId());
jsonObject1.put("count", fundamt.getCountrefundamt());
jsonList.add(jsonObject1);
}
List<JSONObject> jsonList2 = new ArrayList<JSONObject>();
Set<String> set = new HashSet<String>();
for (JSONObject json : jsonList) {
String id1 = json.getString("id");
set.add(id1);
}
for (String str : set) {
int count = 0;
for (JSONObject json : jsonList) {
if (json.getString("id").equals(str)) {
count += (int) json.get("count");
}
}
JSONObject jsonObjects = new JSONObject();
jsonObjects.put("id", str);
jsonObjects.put("count", count);
jsonList2.add(jsonObjects);
}
好啦,以上就是我分享的全部内容啦,请大家多多指教!【ヾ(•ω•`)o~】
最后
以上就是魁梧春天为你收集整理的两个长度不同的list Object数据进行相加运算的全部内容,希望文章能够帮你解决两个长度不同的list Object数据进行相加运算所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复