Here you can find the source of leftPad(String srcString, char c, int length)
public static String leftPad(String srcString, char c, int length)
//package com.java2s; //License from project: Apache License public class Main { public static String leftPad(String srcString, char c, int length) { if (srcString == null) { srcString = ""; }//from ww w.j a v a 2 s . c om int tLen = srcString.length(); if (tLen >= length) return srcString; int iMax = length - tLen; StringBuffer sb = new StringBuffer(); for (int i = 0; i < iMax; ++i) { sb.append(c); } sb.append(srcString); return sb.toString(); } }