Here you can find the source of leftPad(String input, char padding, int length)
public static String leftPad(String input, char padding, int length)
//package com.java2s; //License from project: LGPL public class Main { public static String leftPad(String input, char padding, int length) { if (nullOrEmpty(input)) input = ""; if (input.length() >= length) return input; String padString = createPad(padding, length - input.length()); return padString.concat(input); }//from w w w.j a va 2 s. co m public static boolean nullOrEmpty(String s) { return (s == null) ? true : "".equals(s.trim()); } public static String createPad(char padding, int length) { StringBuilder out = new StringBuilder(); for (int repeat = 0; repeat < length; repeat++) out.append(padding); return out.toString(); } public static String trim(String s) { return emptyIfNull(s).trim(); } public static String emptyIfNull(String s) { return (s == null) ? "" : s; } }