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 str, String pad, int len)
right Pad
String newStr = (str == null ? "" : str);
while (newStr.length() < len) {
    newStr = newStr + pad;
if (newStr.length() > len) {
    newStr = newStr.substring(0, len);
return newStr;
...
StringrightPad(String string, int length)
right Pad
return rightPad(string, length, ' ');
StringrightPad(String strInput, int intLength)
Pad " " to String right side.
byte[] byteResult = new byte[intLength];
byte[] byteInput = strInput.getBytes();
System.arraycopy(byteInput, 0, byteResult, 0, byteInput.length);
for (int i = byteInput.length; i < intLength; i++) {
    byteResult[i] = ' ';
return new String(byteResult);
StringrightPad(String targetStr, char appendChar, int length)
right Pad
if (targetStr == null) {
    return null;
int len = targetStr.length();
while (len++ < length) {
    targetStr += appendChar;
return targetStr;
...
StringrightPad(String toPad, int totalLength)
right Pad
if (toPad == null)
    return null;
if (toPad.length() >= totalLength) {
    return toPad.substring(0, totalLength);
StringBuffer buf = new StringBuffer(toPad);
while (buf.length() < totalLength) {
    buf.append(" ");
...
StringrightPad(String value, int length)
right Pad
StringBuffer buffer = new StringBuffer(value);
while (buffer.length() < length) {
    buffer.append(' ');
return buffer.toString();
StringrightPad(String value, int makeLength, char paddingCharacter)
right Pad
if (makeLength <= 0) {
    throw new IllegalArgumentException("Pad length MUST be over zero");
StringBuffer buffer = new StringBuffer();
buffer.append(value);
buffer.append(buildString(paddingCharacter, makeLength - value.length()));
return buffer.toString();
StringrightPad(String value, int tamanho, String pad)
Adds pad on the right side to complete the size
if (value.length() < tamanho && !pad.isEmpty()) {
    return rightPad(value.concat(pad), tamanho, pad);
return value;
StringBuilderrightPad(StringBuilder pStringBuilder, int pLength, char pChar)
Similar to the Oracle rpad command.
while (pStringBuilder.length() < pLength) {
    pStringBuilder.append(pChar);
return pStringBuilder;
StringrightPadded(String src, int len)
Pad the src to make it [len] bytes with trailing spaces.
return rightPadded(src, len, ' ');