public static String replaceLast(String s,char sub,char with){
  int index=s.lastIndexOf(sub);
  if (index == -1) {
    return s;
  }
  char[] str=s.toCharArray();
  str[index]=with;
  return new String(str);
}

public static String replaceLast ( String s , char sub , char with ) { int index = s . lastIndexOf ( sub ) ; if ( index == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; str [ index ] = with ; return new String ( str ) ; }
replaces the very last occurrence of a character in a string .
