Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Created November 27, 2017 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpeterdelacruz/91711f6045de336994d3a83b166b66e2 to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/91711f6045de336994d3a83b166b66e2 to your computer and use it in GitHub Desktop.
Java 7 Fix
// String.format("%1$#5s", book) does not throw an exception in Java 6,
// but it does in Java 7, so replace this code with a call to the method below,
// e.g. padWithZeroes(book, 5)
private static String padWithZeroes(String s, int length) {
if (s.length() >= length) {
return s;
}
int numZeroes = length - s.length();
StringBuffer buffer = new StringBuffer(numZeroes);
for (int count = 0; count < numZeroes; count++) {
buffer.append("0");
}
return buffer.toString() + s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment