Here you can find the source of leftPad(Object obj, char pad, int len)
public static String leftPad(Object obj, char pad, int len)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { public static String leftPad(Object obj, char pad, int len) { if (obj == null) return null; String str = obj.toString(); int padLen = len - str.length(); if (padLen <= 0) return str; StringBuilder b = new StringBuilder(); for (int i = 0; i < padLen; i++) b.append(pad);/*from www. j a v a2 s . co m*/ b.append(str); return b.toString(); } public static final String toString(Object obj) { return obj == null || isBlank(obj.toString()) ? null : obj.toString().trim(); } public static boolean isBlank(String value) { return value == null || value.trim().length() == 0; } public static String trim(String str, String trim) { int start = 0; while (str.startsWith(trim, start)) start += trim.length(); str = str.substring(start); while (str.endsWith(trim)) str = str.substring(0, str.length() - trim.length()); return str; } }