Java String Pad Left lpad(String src, int length, char padding)

Here you can find the source of lpad(String src, int length, char padding)

Description

lpad

License

Apache License

Parameter

Parameter Description
src a parameter
length a parameter
padding a parameter

Declaration

public static String lpad(String src, int length, char padding) 

Method Source Code

//package com.java2s;
/*//w ww. jav  a2 s .  c o  m
 * Copyright 2011 cruxframework.org.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

public class Main {
    /**
     * @param src
     * @param length
     * @param padding
     * @return
     */
    public static String lpad(String src, int length, char padding) {
        if (src == null) {
            src = "";
        }

        while (src.length() < length) {
            src = padding + src;
        }

        return src;
    }
}

Related

  1. lpad(String s, int len, char ch)
  2. lpad(String s, int len, String padc)
  3. lpad(String s, int length, char pad)
  4. lpad(String s, int width)
  5. lpad(String s, String fill, int len)
  6. lpad(String str, char pad, int len)
  7. lPad(String str, int len, char pad)
  8. lpad(String str, int len, char padding)
  9. LPad(String str, int length, String chr)