Java String Pad Left leftPad(String str, int maxLength, char placeholder)

Here you can find the source of leftPad(String str, int maxLength, char placeholder)

Description

left Pad

License

Open Source License

Declaration

public static String leftPad(String str, int maxLength, char placeholder) 

Method Source Code

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

public class Main {
    public static String leftPad(String str, int maxLength, char placeholder) {

        if (str == null) {
            throw new NullPointerException("str should not be null");
        }//  w w  w.j  a  v  a 2 s.c o  m

        if (maxLength < str.length()) {
            throw new IllegalArgumentException("str length should not be greater than: " + maxLength);
        }

        String temp = str;

        while (temp.length() < maxLength) {
            temp = placeholder + temp;
        }

        return temp;
    }
}

Related

  1. leftPad(String srcString, char c, int length)
  2. leftPad(String str, int len, char c)
  3. leftPad(String str, int length)
  4. leftPad(String str, int length, char c)
  5. leftPad(String str, int length, char padding)
  6. leftPad(String str, int num, String padStr)
  7. leftPad(String str, int pad)
  8. leftPad(String str, int size)
  9. leftPad(String str, int size)