I was looking at John's answers here and thought it was pretty slick. I was wondering if it could be improved further with an if statement, but I'm not sure if an if statement would perform better or not.
Does an if statement "cost more" than changing the value of a String?
String prefix = "";
for (String serverId : serverIds) {
sb.append(prefix);
prefix = ",";
sb.append(serverId);
}
VS.
String prefix = "";
for (String serverId : serverIds) {
sb.append(prefix);
if( prefix.equals( "" ) {
prefix = ",";
}
sb.append(serverId);
}