Here you can find the source of lpad(String str, int len, char padding)
public static String lpad(String str, int len, char padding)
//package com.java2s; //License from project: Open Source License public class Main { public static String lpad(String str, int len, char padding) { if (len < str.length()) { return str.substring(str.length() - len); } else {/*w w w . ja v a 2 s.c o m*/ StringBuffer buf = new StringBuffer(len); int gap = len - str.length(); for (int i = 0; i < gap; i++) { buf.insert(i, padding); } buf.insert(gap, str); return buf.toString(); } } }