Recently i faced this issue of removing the last character in a String if it is a comma.
I wanted to do this with a regular expression although i could have very easily done this by writing some custom code.
This is how you'll do this using regular expression
Pattern pattern = Pattern.compile(",$",0);
It is strange that
did not work for me even though this uses regular expressions internally.
I could have also used
if (string.charAt(string.length()-1) == ',' )