Elements of arraylist duplicated?

I strongly suspect you're adding the same string array each time you go through the loop. You should create a new string array each time Don't forget that the list only contains references So my guess is that your code looks like this: ArrayList tempList = new ArrayList(); String recordArray = new String4; for (int I = 0; I Instead, you want this: ArrayList tempList = new ArrayList(); for (int I = 0; I.

I strongly suspect you're adding the same string array each time you go through the loop. You should create a new string array each time. Don't forget that the list only contains references.So my guess is that your code looks like this: ArrayList tempList = new ArrayList(); String recordArray = new String4; for (int I = 0; I Add(recordArray); } That way you have references to 10 different arrays in the list.

Thank you very much. That was my problem. I was totally confused by the fact that when I try and extract the strings from the list whithin the Do-WHILE loop it worked perfectly yet when I use the same loop to extract the strings but outside of the DO-WHILE loop, I got the same string over and over.

Thanks very much for your help – user702787 Apr 12 at 8:01.

You haven't posted your code so I have to guess, but it sounds like you're adding the same String to your list multiple times and just modifying that single array instance on each iteration of your loop. You need to make sure that you actually allocate a new array on each iterations. Eg: there should be a line something like: recordArray = new Stringsize; inside your loop.

Thank you very much. That was my problem. I changed my code and it's working perfectly.

Thanks again – user702787 Apr 12 at 8:02.

I have created an arraylist and added elements (string array) to it in a DO While loop. I get the correct string for each of the 3 array elements added to the arrayList. The problem is when I try using the same code outside of the DO WHILE loop, the same string is displayed for each of the 3 iterations.

I've searched all over for an answer but can't find one.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions