Here you can find the source of leftPad(String text, int length, char padChar)
public static String leftPad(String text, int length, char padChar)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004-2010 Sunil Kamath (IcemanK). * All rights reserved./*from w ww . ja v a 2 s . c o m*/ * This program is made available under the terms of the Common Public License * v1.0 which is available at http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * Sunil Kamath (IcemanK) - initial API and implementation * *******************************************************************************/ public class Main { public static String leftPad(String text, int length, char padChar) { String text2 = text; if (text2.length() < length) { StringBuffer buf = new StringBuffer(""); //$NON-NLS-1$ for (int i = text2.length(); i < length; i++) { buf.append(padChar); } buf.append(text2); text2 = buf.toString(); } return text2; } public static String toString(Object object, String defaultValue) { if (object == null) { return defaultValue; } else { return object.toString(); } } }