Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Using for loop to get all elements in an ArrayList?


I'm trying to write a method that will use a for loop to iterate through all the positions in an ArrayList and add them to a String. I then want to return that String outside the for loop. Whenever I do this my for loop is ignored and what I initialised the String with is what is returned instead :S

String wordPos = null;
for (int i = 0; i < position.size() - 1; i++)
wordPos = wordPos + position.get(i);

return wordPos;

I hope you can tell me what is going wrong or a better way of doing this.



Sign In or Register to comment.