Java Utililty Methods String Pad Right

List of utility methods to do String Pad Right

Description

The list of methods to do String Pad Right are organized into topic(s).

Method

StringrightPaddedBaseString(String bases, int length)
right Padded Base String
return rightPaddedString(bases, length, '-');
StringrightPaddedString(String string, int length, char paddingChar)
right Padded String
if (string.length() > length) {
    System.err.println("WARNING: String to pad is longer than expected length. Return original string.");
    return string;
if (string.length() == length)
    return string;
return string.concat(String.format("%0" + (length - string.length()) + "d", 0).replace('0', paddingChar));
intrightPadding(int id, int value)
right Padding
return ((int) Math.pow(10, Math.floor(Math.log10(value)) + 1) * id + value);
StringrightPaddWithSpace(String pString_, int stellen)
Add spaces at the right side of a string if necessary.
StringBuffer sbReturn = new StringBuffer(32);
if (pString_ != null) {
    sbReturn.append(pString_);
for (int i = 0; i <= stellen / 8; i++) {
    sbReturn.append("        ");
return sbReturn.toString().substring(0, stellen);
...
StringrightPadInt(int number, int width)
Right pad number with zero's
return rightPad(Integer.toString(number), width, '0');
StringrightPadOrTruncate(String str, int resultSz)
right Pad Or Truncate
if (resultSz < 5)
    throw new IllegalArgumentException("Can't truncate to <5 chars, won't fit ellipsis in");
if (str == null)
    str = "";
if (resultSz >= str.length())
    return rightPad(str, resultSz);
String el = "[...]";
int availSz = resultSz - el.length();
...
StringrightPadString(String str, char pad, int length)
right Pad String
if (str.length() >= length)
    return str;
StringBuffer sb = new StringBuffer(str);
while (sb.length() < length)
    sb.append(pad);
return sb.toString();
voidrightPadString(StringBuilder builder, char padding, int multipleOf)
Pad a StringBuilder to a desired multiple on the right using a specified character.
if (builder == null) {
    throw new IllegalArgumentException("Builder input must not be empty.");
if (multipleOf < 2) {
    throw new IllegalArgumentException("Multiple must be greater than one.");
int needed = multipleOf - (builder.length() % multipleOf);
if (needed < multipleOf) {
...
StringtailPad(String target, String padChar, int length)
tail Pad
if (length == 0 || target.length() >= length) {
    return target;
return tailPad(target + padChar, padChar, length);