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

byte[]rightPad(byte[] bytes, int length, byte padByte)
right Pad
if (bytes == null) {
    return null;
} else if (bytes.length >= length) {
    return bytes;
byte[] newBytes = new byte[length];
System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
for (int i = bytes.length; i < length; i++) {
...
StringrightPad(final String input, final int size)
right Pad
int pads = size - input.length();
if (pads <= 0)
    return input;
StringBuilder out = new StringBuilder(input);
for (int i = pads; i > 0; i--)
    out.append(' ');
return out.toString();
StringrightPad(final String str, final int size, final char padChar)

Right pad a String with a specified character.

The String is padded to the size of size .

 StringUtils.rightPad(null, *, *)     = null StringUtils.rightPad("", 3, 'z')     = "zzz" StringUtils.rightPad("bat", 3, 'z')  = "bat" StringUtils.rightPad("bat", 5, 'z')  = "batzz" StringUtils.rightPad("bat", 1, 'z')  = "bat" StringUtils.rightPad("bat", -1, 'z') = "bat" 
if (str == null) {
    return null;
final int pads = size - str.length();
if (pads <= 0) {
    return str; 
if (pads > PAD_LIMIT) {
...
StringrightPad(String _str, int _size, char _padChar)
right Pad
if (_str == null) {
    return null;
int pads = _size - _str.length();
if (pads <= 0) {
    return _str; 
return _str.concat(padding(pads, _padChar));
...
StringrightPad(String csIn, int nRequiredLength, char cFill)
right Pad
String csOut = new String();
int nLgStringIn = csIn.length();
int nNbcharToPad = nRequiredLength - nLgStringIn;
if (nNbcharToPad > 0) {
    csOut = csIn;
    for (int n = 0; n < nNbcharToPad; n++) {
        csOut = csOut + cFill;
} else 
    csOut = csIn.substring(0, nRequiredLength);
return csOut;
StringrightPad(String field, char padding, int width)
right Pad
String answer;
if (field.length() < width) {
    answer = field + fill(padding, width - field.length());
} else {
    answer = field;
return answer;
StringrightPad(String in, char padding, int length)
right Pad
String out = "";
int toPad = length - in.length();
if (toPad < 0) {
    throw new IllegalArgumentException("Input string longer than requested length");
out = in + getStringRepetition(padding + "", toPad);
return out;
StringrightPad(String in, int len, String pad)
right Pad
for (int i = 0; i < len; i++) {
    in += pad;
return in;
StringrightPad(String input, char padding, int length)
right Pad
if (nullOrEmpty(input))
    input = "";
if (input.length() >= length)
    return input;
String padString = createPad(padding, length - input.length());
return input.concat(padString);
StringrightPad(String input, int length, char pad)
Right pad a string with the specified character, if the string length is less then the specified length.
if (input.length() < length) {
    StringBuilder sb = new StringBuilder();
    sb.append(input);
    for (int i = 0, len = length - input.length(); i < len; i++) {
        sb.append(pad);
    return sb.toString();
return input;