This code works fine in Java 1.6:
public static String padLeft(String s, int n) { if (n <= 0) return s; int noOfSpaces = n * 2; String output; noOfSpaces = s.length() + noOfSpaces; output = String.format("%1$#" + noOfSpaces + "s", s); return output; }
But newer versions (and some other VM implementations) throw this Exception :
java.util.FormatFlagsConversionMismatchException: Mismatched Convertor =s, Flags=
Any workarounds?
source share