Here you can find the source of leftPad(String str, int pad)
public static String leftPad(String str, int pad)
//package com.java2s; // in accordance with the terms of the license agreement accompanying it. public class Main { public static String leftPad(String str, int pad) { if (str == null) return null; if (str.length() >= pad) return str; int len = pad - str.length(); for (int i = 0; i < len; i++) str = " " + str; return str; }/*from w ww .ja va 2 s . co m*/ }