Here you can find the source of leftPad(String str, int length, char padding)
public static String leftPad(String str, int length, char padding)
//package com.java2s; //License from project: Apache License public class Main { public static String leftPad(String str, int length, char padding) { final int paddingLength = length - str.length(); if (paddingLength < 0) return str; final StringBuilder builder = new StringBuilder(length); while (builder.length() < paddingLength) builder.append(padding);//from ww w . j av a2 s. co m builder.append(str); return builder.toString(); } }