Here you can find the source of leftPad(String str, int num, String padStr)
public static String leftPad(String str, int num, String padStr)
//package com.java2s; //License from project: Apache License public class Main { public static String leftPad(String str, int num, String padStr) { if (num <= 0) { return str; }//from w ww .j av a2 s . c o m StringBuilder sb = new StringBuilder(str.length() + num); while (num-- > 0) { sb.append(padStr); } sb.append(str); return sb.toString(); } }