<p>Is there a way to determine if the loop is iterating for the last time. My code looks something like this:</p>

<pre><code>int[] array = {1, 2, 3...};
StringBuilder builder = new StringBuilder();

for(int i : array)
{
    builder.append("" + i);
    if(!lastiteration)
        builder.append(",");
}
</code></pre>

<p>Now the thing is I don't want to append the comma in the last iteration. Now is there a way to determine if it is the last iteration or am I stuck with the for loop or using an external counter to keep track.</p>

It might be easier to always append. And then, when you're done with your loop, just remove the final character. Tons less conditionals that way too.
You can use
```
StringBuilder
```
's
```
deleteCharAt(int index)
```
with index being
```
length() - 1
```