Here you can find the source of lpad(int value, int padLen, char padChar)
Parameter | Description |
---|---|
value | a int value. |
padLen | the total length of the return value. |
padChar | padded character. |
public static String lpad(int value, int padLen, char padChar)
//package com.java2s; //License from project: Open Source License public class Main { /**/* ww w. jav a 2s . c o m*/ * Returns value argument, left-padded to length padLen argument with the * sequence of character in padChar argument. * * If the value argument is null, value argument think of empty string * (""). * * @param value * a string value. * @param padLen * the total length of the return value. * @param padChar * padded character. * @return left padded string. */ public static String lpad(String value, int padLen, char padChar) { if (value == null) value = ""; while (value.length() < padLen) { value = padChar + value; } return value; } /** * Returns value argument, left-padded to length padLen argument with the * sequence of character in padChar argument. * * @param value * a short value. * @param padLen * the total length of the return value. * @param padChar * padded character. * @return left padded string. */ public static String lpad(short value, int padLen, char padChar) { return lpad(String.valueOf(value), padLen, padChar); } /** * Returns value argument, left-padded to length padLen argument with the * sequence of character in padChar argument. * * @param value * a int value. * @param padLen * the total length of the return value. * @param padChar * padded character. * @return left padded string. */ public static String lpad(int value, int padLen, char padChar) { return lpad(String.valueOf(value), padLen, padChar); } /** * Returns value argument, left-padded to length padLen argument with the * sequence of character in padChar argument. * * @param value * a long value. * @param padLen * the total length of the return value. * @param padChar * padded character. * @return left padded string. */ public static String lpad(long value, int padLen, char padChar) { return lpad(String.valueOf(value), padLen, padChar); } /** * Returns value argument, left-padded to length padLen argument with the * sequence of character in padChar argument. * * @param value * a float value. * @param padLen * the total length of the return value. * @param padChar * padded character. * @return left padded string. */ public static String lpad(float value, int padLen, char padChar) { return lpad(String.valueOf(value), padLen, padChar); } /** * Returns value argument, left-padded to length padLen argument with the * sequence of character in padChar argument. * * @param value * a double value. * @param padLen * the total length of the return value. * @param padChar * padded character. * @return left padded string. */ public static String lpad(double value, int padLen, char padChar) { return lpad(String.valueOf(value), padLen, padChar); } }