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, int size)
Right pad a String with spaces.
return rightPad(str, size, " ");
StringrightPad(String str, int size)
right Pad
return rightPad(str, size, ' ');
StringrightPad(String str, int size)
right Pad
return rightPad(str, size, ' ');
StringrightPad(String str, int size, 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;
int pads = size - str.length();
if (pads <= 0) {
    return str; 
if (pads > PAD_LIMIT) {
...
StringrightPad(String str, int size, 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;
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; 
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; 
if (pads > PAD_LIMIT) {
...
StringrightPad(String str, int size, String padStr)
right Pad
if (str == null) {
    return null;
if (isEmpty(padStr)) {
    padStr = " ";
int padLen = padStr.length();
int strLen = str.length();
...
StringrightPad(String str, int width)
right Pad
return rightPad(str, width, ' ');
StringrightPad(String str, int width, char padding)
right Pad
StringBuilder buff = new StringBuilder(str);
for (int i = 0; i < width; ++i) {
    buff.append(padding);
return buff.substring(0, width);