Why does it add another "," after the last element of the array?
Since there is nothing special about the last element, you add at the end of each element.
How to prevent this?
You can try using the usual for -loop and add only if the index you specified is not the last index of the array. Equivalently, you can add before each element except the first one and you will get the same effect.
int len = gamesArray.length; if (len > 0) System.out.println(gamesArray[0]); for (int i = 1; i < len; i++) System.out.print(", " + gamesArray[i]);
source share