Java String Pad Left leftPad(String str, int num, String padStr)

Here you can find the source of leftPad(String str, int num, String padStr)

Description

left Pad

License

Apache License

Declaration

public static String leftPad(String str, int num, String padStr) 

Method Source Code

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

public class Main {
    public static String leftPad(String str, int num, String padStr) {
        if (num <= 0) {
            return str;
        }//from w  ww .j av a2  s  . c  o m
        StringBuilder sb = new StringBuilder(str.length() + num);
        while (num-- > 0) {
            sb.append(padStr);
        }
        sb.append(str);
        return sb.toString();
    }
}

Related

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