Check out example codes for "string replace last character java". It will help you in understanding the concepts better.

Code Example 1

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

Learn ReactJs, React Native from akashmittal.com