Here you can find the source of lpad(String s, int length, char pad)
private static String lpad(String s, int length, char pad)
//package com.java2s; //License from project: Open Source License public class Main { private static String lpad(String s, int length, char pad) { if (s == null || s.length() >= length) { return s; }//from w w w . j a v a2s. c o m StringBuilder result = new StringBuilder(length); int padSize = length - s.length(); while (padSize > 0) { result.append(pad); padSize--; } result.append(s); return result.toString(); } }