Java String Pad Left lPad(String string, char[] padding, int length)

Here you can find the source of lPad(String string, char[] padding, int length)

Description

Pads the supplied String with padding chars on the left to the specified length and returns the result as a new String.;

License

LGPL

Parameter

Parameter Description
string the original String to pad.
padding a parameter
length a parameter

Declaration

public static final String lPad(String string, char[] padding, int length) 

Method Source Code

//package com.java2s;
/**/*from w ww .  j  a  v  a 2 s  .c  o m*/
 * Converts a line of text into an array of lower case words using a
 * BreakIterator.wordInstance(). <p>
 *
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 *
 * @param text a String of text to convert into an array of words
 * @return text broken up into an array of words.
 */

public class Main {
    /**
     *  Pads the supplied String with padding chars on the left to the specified length and returns
     * the result as a new String.;
     * @param string the original String to pad.
     * @param padding
     * @param length
     * @return
     */
    public static final String lPad(String string, char[] padding, int length) {
        if (string == null || string.length() > length) {
            return string;
        }
        StringBuffer buf = new StringBuffer(length);
        buf.append(padding, 0, length - string.length()).append(string);
        return buf.toString();
    }
}

Related

  1. LPad(String str, int length, String chr)
  2. lPad(String str, int length, String padString)
  3. lpad(String str, int size)
  4. lpad(String str, int totalPadAmount, String padChar)
  5. lpad(String str, String chr, int length)
  6. lPad(String target, String fix, int length)
  7. lPad(String val, int length, String padChar)
  8. lpadding(String s, int n, String padding)
  9. lpadSapce(final String src, final int length)