In current code, spaces are being added before the strings and the i < strings.size() check has no affect. Although before returning, the final string is being trimmed. We can fix the space addition bug and avoid the trim.
Also one more bug is, if the sep parameter is not space, then the trim() method won't remove the the separator from the beginning of the final string: sep + strings[0] + sep + strings[1] + sep + ..... + sep + strings[n - 1]. This PR fixes that too.
In current code, spaces are being added before the strings and the
i < strings.size()
check has no affect. Although before returning, the final string is being trimmed. We can fix the space addition bug and avoid the trim.Also one more bug is, if the
sep
parameter is notspace
, then thetrim()
method won't remove the the separator from the beginning of the final string:sep + strings[0] + sep + strings[1] + sep + ..... + sep + strings[n - 1]
. This PR fixes that too.