Android String Pad padLeft(String str, char padding, int upTo)

Here you can find the source of padLeft(String str, char padding, int upTo)

Description

Pad a string on the left until it reaches the designated height

Parameter

Parameter Description
str a parameter
padding a parameter
upTo a parameter

Declaration

public static String padLeft(String str, char padding, int upTo) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*ww w.  ja v  a  2 s  .  c o m*/
     * Pad a string on the left until it reaches the designated height
     * @param str
     * @param padding
     * @param upTo
     * @return
     */
    public static String padLeft(String str, char padding, int upTo) {

        StringBuilder stringBuilder = new StringBuilder(str);

        while (stringBuilder.length() < upTo) {
            stringBuilder.insert(0, padding);
        }

        return stringBuilder.toString();

    }
}

Related

  1. toPaddedString(String source, int length, char pad, boolean trailing)
  2. toPaddedString(String source, int length, String pad, boolean trailing)
  3. padString(String source)