public static String removeLast(String original,String string){
  int lastIndexOf=original.lastIndexOf(string);
  if (lastIndexOf == -1) {
    return original;
  }
  return original.substring(0,lastIndexOf);
}

public static String removeLast ( String original , String string ) { int lastIndexOf = original . lastIndexOf ( string ) ; if ( lastIndexOf == - 1 ) { return original ; } return original . substring ( 0 , lastIndexOf ) ; }
this method create nre properties from the origianl one and remove any key with the password , then call tostring method on this prperties .
