Here you can find the source of leftPadString(String str, char pad, int length)
public static String leftPadString(String str, char pad, int length)
//package com.java2s; //License from project: Apache License public class Main { public static String leftPadString(String str, char pad, int length) { if (str.length() >= length) return str; StringBuffer sb = new StringBuffer(); while (sb.length() < length - str.length()) sb.append(pad);/*from w ww. j a va 2 s.com*/ sb.append(str); return sb.toString(); } }