I suggest you to use Regex. It is short and more readable:
String result = text.replaceAll(",+", "");