Java String Pad Left leftPad(String str, int length, char padding)

Here you can find the source of leftPad(String str, int length, char padding)

Description

left Pad

License

Apache License

Declaration

public static String leftPad(String str, int length, char padding) 

Method Source Code

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

public class Main {
    public static String leftPad(String str, int length, char padding) {
        final int paddingLength = length - str.length();
        if (paddingLength < 0)
            return str;

        final StringBuilder builder = new StringBuilder(length);

        while (builder.length() < paddingLength)
            builder.append(padding);//from  ww w .  j  av a2 s. co  m

        builder.append(str);

        return builder.toString();
    }
}

Related

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