string replace last character java

Java
if(fieldName.endsWith(","))
{
  fieldName = fieldName.substring(0,fieldName.length() - 1);
}
Source

Also in Java: