stmn1320
骑驴快跑
2012-12-28 10:37

判断list取值完毕

  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术

定义了两个list,listRkd得到数据库的值,拼接成字符串后放到了list.add里,进入循环的时候出现异常了,假如for循环现在要循环10次,我的list里的值现在只有8个值,那么我用showData.apend(list.get(i))循环取list的值到第八次就取完了,第九次执行show.append(",")就会报错,我怎么在show.append(",")外面做个判断,判断list.get(i)的值已经去完了,不用在进行字符串拼接了,或者进来让第九次和第十次执行空循环也行
[code="java"]
String start = request.getParameter("start");
String limit = request.getParameter("limit");
Integer startInt = Integer.parseInt(start);
Integer limitInt = Integer.parseInt(limit);
RukudanDAO rkdDAO = new RukudanDAO();
List list = new ArrayList();
int rkCount = rkdDAO.RkCount();
List listRkd = rkdDAO.GetRKInfo();
Iterator iter = listRkd.iterator();
while (iter.hasNext()) {
Rkd rkd = iter.next();
StringBuffer data = new StringBuffer();
data.append("{wh:").append(rkd.getWh()).append(",rq:'")
.append(rkd.getRq() + "'").append(",bmmc:'")
.append(rkd.getBmmc() + "'").append(",gysmc:'")
.append(rkd.getGysmc() + "'").append(",ckmc:'")
.append(rkd.getCkmc() + "'").append(",slhj:'")
.append(rkd.getSlhj() + "'").append(",jehj:'")
.append(rkd.getJehj() + "'").append(",zy:'")
.append(rkd.getZy() + "'").append(",cg:'")
.append(rkd.getCg() + "'").append(",bg:'")
.append(rkd.getBg() + "'").append(",jz:'")
.append(rkd.getJz() + "'").append(",czy:'")
.append(rkd.getCzy() + "'").append("}");
list.add(data.toString());
System.out.print(data.toString());

}
StringBuffer showData = new StringBuffer();
int end = startInt+limitInt;
for(int i=startInt;i<end;i++){
    showData.append(list.get(i));
    if(i!=end){
        showData.append(",");
    }
}

[/code]

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐