Here you can find the source of leftPad(String inStr, int length, char paddingChar)
Parameter | Description |
---|---|
inStr | Input string |
length | Padding length |
paddingChar | Padding character |
public static String leftPad(String inStr, int length, char paddingChar)
//package com.java2s; public class Main { /**/*from w w w .j a v a 2 s .com*/ * Left padding the string with the specified padding character upto the specified length. * @param inStr Input string * @param length Padding length * @param paddingChar Padding character * @return Padding string */ public static String leftPad(String inStr, int length, char paddingChar) { if (inStr.length() == length) return inStr; StringBuffer outStr = new StringBuffer(); for (int i = inStr.length(); i < length; i++) { outStr.append(paddingChar); } outStr.append(inStr); return outStr.toString(); } /** * Converts object to a string.<br> * If object is null then return null * * @param obj * @return */ public static String toString(Object obj) { if (null == obj) { return null; } else { return obj.toString(); } } }