Your condition is wrong: instead of (i - 1) == users.size()
use (i + 1) == users.size()
or i == users.size() - 1
.
Basically (i - 1) == users.size()
would match the element after the last (which clearly doesn't exist), i.e. for a list of size 5 you'd get (i - 1) == 5
or i == 6
.
In the example above (i + 1) == users.size()
and i == users.size() - 1
would resolve to (i + 1) == 5
and i == 5 - 1
which both result in i == 4
, which is the last index in the list.
Edit: Btw, your loop is still quite odd. You basically seem to add a line break after each but the last element. Why don't you change it to something like this:
String msg = "---Player List, Count:" + users.size() + "---" + brln;
for (int i = 0; i < users.size(); i++) {
if( i > 0){
msg += brln;
}
msg += "--::" + users.get(i).name;
}
This would add a line break before every line except the first. Note how the condition is much easier.