Here you can find the source of leftPad(String string, int length)
public static String leftPad(String string, int length)
//package com.java2s; //License from project: Open Source License public class Main { public static String leftPad(String string, int length) { return leftPad(string, length, ' '); }/*from w w w. j av a 2 s. c o m*/ public static String leftPad(String string, int length, char ch) { if (string == null || string.length() >= length) return string; StringBuffer sb = new StringBuffer(length); for (int i = (string.length() - 1); i < length - 1; i++) sb.append(ch); return sb.append(string).toString(); } }