Here you can find the source of leftPad(String _str, int _size, char _padChar)
public static String leftPad(String _str, int _size, char _padChar)
//package com.java2s; public class Main { public static String leftPad(String _str, int _size, char _padChar) { if (_str == null) { return null; }/*from www.j a v a2s . c om*/ int pads = _size - _str.length(); if (pads <= 0) { return _str; // returns original String when possible } return padding(pads, _padChar).concat(_str); } private static String padding(int _repeat, char _padChar) { String value = ""; String padStr = String.valueOf(_padChar); if (_repeat > 0) { for (int i = 0; i < _repeat; i++) { value = value.concat(padStr); } } return value; } }