list循环遍历
程序员文章站
2024-01-30 20:17:46
...
list循环遍历
普通for循环
List<B2bEconomicsBankCompanyDto> ebcList = new ArrayList<B2bEconomicsBankCompanyDto>();
B2bEconomicsBankCompanyDto ebc = new B2bEconomicsBankCompanyDto();
JSONArray jsonArray = jsonObject.getJSONArray("list_obj");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject json = (JSONObject) jsonArray.get(i);
Integer type = json.getInteger("type");//额度品种代码(金融产品类型)
String startDate = json.getString("startDate");//额度生效日期
String endDate = json.getString("endDate");//额度到期日
Double amount = json.getDouble("amount");//产品授信额度
Double availableAmount = json.getDouble("availableAmount");//产品可用额度
ebc.setType(type);
ebc.setCreditStartTime(DateUtil.parseDateFormatYMD(startDate));
ebc.setCreditEndTime(DateUtil.parseDateFormatYMD(endDate));
ebc.setContractAmount(amount);
ebc.setAvailableAmount(availableAmount);
}
Double totalAmount = jsonObject.getDouble("totalAmount"); //授信总额度
ebc.setCreditAmount(totalAmount);
ebc.setPk(KeyUtils.getUUID());
ebc.setCompanyPk(company.getPk());
ebc.setBankPk(dto.getBankPk());
ebcList.add(ebc);
resp.setEbcList(ebcList);
加强for循环
List<HxhHistoryDto> list = hxhHistoryDao.searchHistoryList(map);
List<HxhHistoryDto> historyDtoList = new ArrayList<HxhHistoryDto>();
for (HxhHistoryDto dto : list) {
if ("index".equals(dto.getType())) {
dto.setType("首页");
} else if ("bill".equals(dto.getType())) {
dto.setType("我的账单");
} else if ("order".equals(dto.getType())) {
dto.setType("订单");
} else if ("contract".equals(dto.getType())) {
dto.setType("合同");
} else if ("complaint".equals(dto.getType())) {
dto.setType("投诉");
} else if ("account".equals(dto.getType())) {
dto.setType("我的信息");
} else if ("quotation".equals(dto.getType())) {
dto.setType("报价");
} else if ("news".equals(dto.getType())) {
dto.setType("行业资讯");
} else if ("dynamic".equals(dto.getType())) {
dto.setType("盛虹动态");
}
historyDtoList.add(dto);
}
iterator遍历
List<HxhHistoryDto> list = hxhHistoryDao.searchHistoryList(map);
List<HxhHistoryDto> historyDtoList = new ArrayList<HxhHistoryDto>();
Iterator<HxhHistoryDto> it = list.iterator();
while (it.hasNext()) {
HxhHistoryDto dto = it.next();
if ("index".equals(dto.getType())) {
dto.setType("首页");
} else if ("bill".equals(dto.getType())) {
dto.setType("我的账单");
} else if ("order".equals(dto.getType())) {
dto.setType("订单");
} else if ("contract".equals(dto.getType())) {
dto.setType("合同");
} else if ("complaint".equals(dto.getType())) {
dto.setType("投诉");
} else if ("account".equals(dto.getType())) {
dto.setType("我的信息");
} else if ("quotation".equals(dto.getType())) {
dto.setType("报价");
} else if ("news".equals(dto.getType())) {
dto.setType("行业资讯");
} else if ("dynamic".equals(dto.getType())) {
dto.setType("盛虹动态");
}
historyDtoList.add(dto);
}