Java String Pad Left lPad(String target, String fix, int length)

Here you can find the source of lPad(String target, String fix, int length)

Description

l Pad

License

Apache License

Declaration

public static String lPad(String target, String fix, int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String lPad(String target, String fix, int length) {
        if ((target == null) || (fix == null) || (target.length() >= length))
            return target;
        StringBuffer newStr = new StringBuffer();
        for (int i = 0; i < length - target.length(); i++) {
            newStr.append(fix);//from   w  w  w .  ja v a  2s .  c  o  m
        }
        return newStr.append(target).toString();
    }

    public static String toString(Object obj) {
        if (obj == null) {
            return "";
        }
        return obj.toString();
    }

    public static String toString(Object obj, String defaultStr) {
        if (obj == null) {
            return defaultStr;
        }
        return obj.toString();
    }
}

Related

  1. lPad(String str, int length, String padString)
  2. lpad(String str, int size)
  3. lpad(String str, int totalPadAmount, String padChar)
  4. lpad(String str, String chr, int length)
  5. lPad(String string, char[] padding, int length)
  6. lPad(String val, int length, String padChar)
  7. lpadding(String s, int n, String padding)
  8. lpadSapce(final String src, final int length)
  9. lpadWithCount(String input, String str, int count)