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 s, int width)
pad on right side of string to width.
String tmp = "";
int npad = width - s.length();
if (npad < 0)
    tmp = s.substring(0, width);
else if (npad == 0)
    tmp = s;
else {
    tmp = s;
...
StringrightPad(String s, int z)
Right pad a String with spaces.
return rightPad(s, z, " ");
StringrightPad(String srcStr, char padChar, int destLen)
right Pad
if (srcStr == null) {
    return genStr(padChar, destLen);
} else if (srcStr.length() < destLen) {
    StringBuilder destSrc = new StringBuilder(destLen);
    destSrc.append(srcStr);
    for (int i = srcStr.length(); i < destLen; i++) {
        destSrc.append(padChar);
    return destSrc.toString();
} else {
    return srcStr;
StringrightPad(String srcString, char c, int length)
right Pad
if (srcString == null) {
    srcString = "";
int tLen = srcString.length();
if (tLen >= length)
    return srcString;
int iMax = length - tLen;
StringBuffer sb = new StringBuffer();
...
StringrightPad(String str, int len, char c)
right Pad
if (str.length() >= len)
    return str;
StringBuilder ret = new StringBuilder(str);
while (ret.length() < len)
    ret.append(c);
return ret.toString();
StringrightPad(String str, int length, char padding)
right Pad
if (str == null) {
    str = "";
if (length == 0 || str.length() > length) {
    return str;
for (int i = str.length(); i < length; i++) {
    str += padding;
...
StringrightPad(String str, int max, char pad)
right Pad
StringBuilder builder = new StringBuilder(str);
builder.setLength(max);
for (int index = str.length(); index < max; index++) {
    builder.setCharAt(index, pad);
return builder.toString();
StringrightPad(String str, int num, String padStr)
right Pad
if (num <= 0) {
    return str;
StringBuilder sb = new StringBuilder(str.length() + num);
sb.append(str);
while (num-- > 0) {
    sb.append(padStr);
return sb.toString();
StringrightPad(String str, int size)
right Pad
return rightPad(str, size, ' ');
StringrightPad(String str, int size)
right Pad
return rightPad(str, size, ' ');