Here you can find the source of leftPad(String aStr, int aLen)
Parameter | Description |
---|---|
aStr | the string |
aLen | length of field |
public static String leftPad(String aStr, int aLen)
//package com.java2s; //License from project: LGPL public class Main { /**/*from ww w.j a va 2 s .com*/ * Right-justify a String in a field, padding left with blank. * * @param aStr the string * @param aLen length of field * @return the right-justified string */ public static String leftPad(String aStr, int aLen) { return replicate(' ', aLen - aStr.length()) + aStr; } /** * Right-justify each String uniformly in in an Array of String, * padding left with blank. * * @param aLines the Strings to justify * @param aLen uniform field length of output strings * @return Array of right-justified string */ public static String[] leftPad(String aLines[], int aLen) { for (int idx = 0; idx < aLines.length; idx++) { aLines[idx] = leftPad(aLines[idx], aLen); } return aLines; } /** * Create a String filled with a single character * * @param aChar the character to fill with * @param aLen how many to fill with * @return A string consisting of the char repeated aLen times */ public static String replicate(char aChar, int aLen) { StringBuffer mBuf = new StringBuffer(aLen); for (int mIdx = 0; mIdx < aLen; mIdx++) { mBuf.append(aChar); } return mBuf.toString(); } }