public static String replaceLast(String s,String sub,String with){
  int i=s.lastIndexOf(sub);
  if (i == -1) {
    return s;
  }
  return s.substring(0,i) + with + s.substring(i + sub.length());
}

public static String replaceLast ( String s , String sub , String with ) { int i = s . lastIndexOf ( sub ) ; if ( i == - 1 ) { return s ; } return s . substring ( 0 , i ) + with + s . substring ( i + sub . length ( ) ) ; }
replaces the very last occurrence of a substring with supplied string .
