List of utility methods to do String Pad from Left
String | lpad(String str, int length) lpad if (isBlank(str)) return ""; int j = str.length(); for (int i = j; i < length; i++) { str = "0" + str; return str; |
String | padding(int width) Returns space padding if (width < 0) throw new IllegalArgumentException("width must be > 0"); if (width < padding.length) return padding[width]; char[] out = new char[width]; for (int i = 0; i < width; i++) out[i] = ' '; return String.valueOf(out); ... |
String | padLeft(String input, int size) Pad the specified number of spaces to the input string to make it that length if (input.length() > size) { throw new IllegalArgumentException( "input must be shorter than or equal to the number of spaces: " + size); StringBuilder sb = new StringBuilder(); for (int i = input.length(); i < size; i++) { sb.append(" "); ... |
String | prefixPad(String toPad, String padLetter, int targetLength) prefix Pad if (toPad == null) toPad = ""; while (toPad.length() < targetLength) { toPad = padLetter + toPad; return toPad; |