Java String Pad Left leftPad(String str, int pad)

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

Description

left Pad

License

Open Source License

Declaration

public static String leftPad(String str, int pad) 

Method Source Code

//package com.java2s;
//  in accordance with the terms of the license agreement accompanying it.

public class Main {
    public static String leftPad(String str, int pad) {
        if (str == null)
            return null;

        if (str.length() >= pad)
            return str;

        int len = pad - str.length();

        for (int i = 0; i < len; i++)
            str = " " + str;

        return str;
    }/*from w ww .ja  va 2  s  . co m*/
}

Related

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