Using for loop to get all elements in an ArrayList? - Programmers Heaven

Howdy, Stranger!

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

Categories

Using for loop to get all elements in an ArrayList?

Hi,

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

[code]
String wordPos = null;
for (int i = 0; i < position.size() - 1; i++)
{
wordPos = wordPos + position.get(i);
}

return wordPos;
[/code]

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

Thanks

Comments

Sign In or Register to comment.