I had a perfectly working code yesterday, in the exact form of:
int lastRecord = 1; String key = String.format(\"%08d\", Integer.toString(lastRecord));
You don't need the Integer.toString():
Integer.toString()
newPK = String.format("%08d", lastRecord);
String.format() will do the conversion and the padding.
String.format()