Here you can find the source of leftPaddedString(String string, int length, char paddingChar)
public static String leftPaddedString(String string, int length, char paddingChar)
//package com.java2s; //License from project: Open Source License public class Main { public static String leftPaddedString(String string, int length, char paddingChar) { if (string.length() > length) { System.err.println("WARNING: String to pad is longer than expected length. Return original string."); return string; }//from ww w . ja v a 2s . co m if (string.length() == length) return string; return String.format("%0" + (length - string.length()) + "d", 0).replace('0', paddingChar).concat(string); } }