Android String Pad from Left padding(int width)

Here you can find the source of padding(int width)

Description

Returns space padding

Parameter

Parameter Description
width amount of padding desired

Return

string of spaces * width

Declaration

public static String padding(int width) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String[] padding = { "", " ", "  ", "   ", "    ",
            "     ", "      ", "       ", "        ", "         ",
            "          " };

    /**/*from  www .  j a  v a2  s. co  m*/
     * Returns space padding
     * 
     * @param width
     *            amount of padding desired
     * @return string of spaces * width
     */
    public static String padding(int width) {
        if (width < 0)
            throw new IllegalArgumentException("width must be > 0");

        if (width < padding.length)
            return padding[width];

        char[] out = new char[width];
        for (int i = 0; i < width; i++)
            out[i] = ' ';
        return String.valueOf(out);
    }
}

Related

  1. lpad(String str, int length)
  2. padLeft(String input, int size)
  3. prefixPad(String toPad, String padLetter, int targetLength)