Here you can find the source of leftPad(String str, int len, char c)
public static String leftPad(String str, int len, char c)
//package com.java2s; //License from project: Open Source License public class Main { public static String leftPad(String str, int len, char c) { if (str.length() >= len) return str; StringBuilder ret = new StringBuilder(); while (ret.length() < len - str.length()) ret.append(c);/*from w w w. j a v a2 s . c o m*/ return ret.append(str).toString(); } public static String leftPad(String str, int len) { return leftPad(str, len, ' '); } }