Java String Pad Left leftPad(String str, int len, char c)

Here you can find the source of leftPad(String str, int len, char c)

Description

left Pad

License

Open Source License

Declaration

public static String leftPad(String str, int len, char c) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String leftPad(String str, int len, char c) {
        if (str.length() >= len)
            return str;
        StringBuilder ret = new StringBuilder();
        while (ret.length() < len - str.length())
            ret.append(c);/*from w  w  w.  j  a  v a2 s .  c o  m*/
        return ret.append(str).toString();
    }

    public static String leftPad(String str, int len) {
        return leftPad(str, len, ' ');
    }
}

Related

  1. leftPad(String s, int width)
  2. leftPad(String s, int z)
  3. leftPad(String srcStr, char padChar, int destLen)
  4. leftPad(String srcString, char c, int length)
  5. leftPad(String srcString, char c, int length)
  6. leftPad(String str, int length)
  7. leftPad(String str, int length, char c)
  8. leftPad(String str, int length, char padding)
  9. leftPad(String str, int maxLength, char placeholder)