java如何用for循环遍历list集合?

和遍历数组不太一样,但是又有相似性,

用list.size() 表示list的长度(类似于数组的.length属性),用list.get(i)表示list中指定的元素(类似于数组的下标表示法:Arrays[i])。

具体代码如下:

if(list != null){
for(int i = 0 ; i < list.size() ; i++){
CountVoucherResponse countVoucher = list.get(i);
WeCahtQueryVoucherResponse weCahtQueryVoucherResponse = new WeCahtQueryVoucherResponse();
countVoucher.setCustomerId(customerId);
countVoucher.setTime(time);
List<CountVoucherResponse> queryInfoList = this.voucherDao.queryInfoByVoucherId(countVoucher);
if(queryInfoList != null && queryInfoList.size() > 0 ){
CountVoucherResponse queryInfo = queryInfoList.get(0);
weCahtQueryVoucherResponse.setNum(countVoucher.getNum());
weCahtQueryVoucherResponse.setMinTime(countVoucher.getMinTime());
weCahtQueryVoucherResponse.setMaxTime(countVoucher.getMaxTime());
StringBuffer voucherName = new StringBuffer();
if(queryInfo.getPromotionName() != null){
voucherName.append(queryInfo.getPromotionName());
weCahtQueryVoucherResponse.setPromotionName(voucherName.toString());
}
if(queryInfo.getTypeName() != null){
voucherName.append(queryInfo.getTypeName());
weCahtQueryVoucherResponse.setVoucherName(voucherName.toString());
}
if(queryInfo.getDiscountMoney() != null){
weCahtQueryVoucherResponse.setDiscountMoney(queryInfo.getDiscountMoney());
}
if(queryInfo.getDiscountNum() != null){
weCahtQueryVoucherResponse.setDiscountNum(queryInfo.getDiscountNum());
}
if(queryInfo.getTargetId() != null){
Goodsh goodsh = this.goodshDao.selectGoods(queryInfo.getTargetId());
if(goodsh != null){
weCahtQueryVoucherResponse.setTargetName(goodsh.getName());
}
}
weCahtQueryVoucherResponse.setCustomerId(customerId);
weCahtQueryVoucherResponse.setPromtionId(queryInfo.getPromtionId());
String[] voucherIds = new String[queryInfoList.size()];
for(int j = 0; j<queryInfoList.size(); j++){
voucherIds[j] = queryInfoList.get(i).getVoucherId();
}
weCahtQueryVoucherResponse.setVoucherIds(voucherIds);
queryResponseList.add(weCahtQueryVoucherResponse);
}
}
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值