0

I have an ArrayList in JSP that is storing values that I have from exploding a string. These values are numbers. I can print the Arraylist out to the page just fine and I can also access individual values just fine. However, when I go to put the ArrayList in a for loop to loop through the values the page will not load(how the serer is set up).

Here's the code for what I am trying:

String dds = request.getParameter("dds"); 
    //"1,2,3,4,5,6,7";
String ddm = "this";
ArrayList ddr=new ArrayList();
if(dds == "null" || dds == null){
    ddr.add("99");
}else{
String[] ddq = dds.split(",");
int g = 0;
for(g=0;g<ddq.length;g++){
    ddr.add(ddq[g]);
}
}

This works fine and then here are the things I have tried that work (for my tests I just made the ArrayList = 1,2,3,4,5,6,7,8):

int h=0;
 for(h=0;h<ddr.size();h++){
    if(h>0){           
     out.print(","+ddr.get(h));
    }else{
     out.print(ddr.get(h));
    }

It also works if I just call:

ddr.get(0)

But the when I try to throw it in an if statement it does not work. Like so:

 int h=0;
 for(h=0;h<ddr.size();h++){
    if(ddr.get(h) == i){           
     out.print("This does not work");
    }
}

Also I have tried converting it to an int:

if(Integer.parseInt(ddr.get(h)) == i)

But this just leads to the page not loading again.

This may be something simple and I'm just missing it. But I'm just trying to add a feature to preexisting code I didn't make in the first place. Thanks for any help beforehand.

4

1 回答 1

0

我想通了。这有点令人费解,所以我仍然对其他想法持开放态度,但它完成了工作。我所做的是将我正在比较的值和数组值都转换为字符串,然后再转换回整数。我不知道为什么这有效,只是做数组值没有,但它似乎已经成功了。

于 2012-08-20T20:12:07.050 回答