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

StringrightPad(String inStr, int length, char paddingChar)
Right padding the string with the specified padding character upto the specified length.
if (inStr.length() == length)
    return inStr;
StringBuffer outStr = new StringBuffer();
outStr.append(inStr);
for (int i = inStr.length(); i < length; i++) {
    outStr.append(paddingChar);
return outStr.toString();
...
StringrightPad(String original, int length, char padChar)
Pads the String with the given character until it has the given length.
if (original.length() >= length) {
    return original;
return original + stringOfChar(padChar, length - original.length());
StringrightPad(String originalText, int length, char fillChar)
right Pad
StringBuilder sb = new StringBuilder();
length = length - originalText.length();
sb.append(originalText);
for (int i = 0; i < length; i++) {
    sb.append(fillChar);
return sb.toString();
StringrightPad(String ret, int limit)
Right pad a string: adds spaces to a string until a certain length.
if (ret == null)
    return rightPad(new StringBuffer(), limit);
else
    return rightPad(new StringBuffer(ret), limit);
StringrightPad(String s, int length)
right Pad
if (s == null)
    s = "";
if (s.length() > length)
    return s.substring(0, length);
return s + repeat(" ", length - s.length());
StringrightPad(String s, int length)
right pad with spaces
String p = "                                                          ";
return s + p.substring(s.length() + (p.length() - length));
StringrightPad(String s, int length)
Returns a copy of s padded with trailing spaces so that it's length is length.
StringBuffer sb = new StringBuffer(s);
for (int i = length - s.length(); i > 0; i--)
    sb.append(" ");
return sb.toString();
StringrightPad(String s, int minLength)
Pads the string at the right with spaces until it reaches the desired length.
return rightPad(s, minLength, ' ');
StringrightPad(String s, int minLength, char filling)
right Pad
int ln = s.getBytes().length;
if (minLength <= ln) {
    return s;
StringBuilder res = new StringBuilder(minLength);
res.append(s);
int dif = minLength - ln;
for (int i = 0; i < dif; i++) {
...
StringrightPad(String s, int n)
right Pad
return String.format("%1$-" + n + "s", s);