Created
November 27, 2017 17:56
-
-
Save bjpeterdelacruz/91711f6045de336994d3a83b166b66e2 to your computer and use it in GitHub Desktop.
Java 7 Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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