Java Utililty Methods String Align Right

List of utility methods to do String Align Right

Description

The list of methods to do String Align Right are organized into topic(s).

Method

StringalignRight(CharSequence cs, int width, char c)
align Right
if (null == cs)
    return null;
int len = cs.length();
if (len >= width)
    return cs.toString();
return new StringBuilder().append(dup(c, width - len)).append(cs).toString();
StringalignRight(final long number, final int length)
Trim an integer with leading spaces to a given maximum length.
return alignRight("" + number, length);
StringalignRight(final Object str, final int size)
align Right
return alignRight(str.toString(), size, ' ');
StringalignRight(String data)
align Right
int dataLength = data.length();
String padding = " ";
for (int i = 0; i < TOTAL_PAGE_LENGTH - dataLength; i++) {
    padding = padding + " ";
return padding + data;
StringalignRight(String str, int length, boolean isEllipsis)
align Right
if (str.length() <= length) {
    StringBuffer temp = new StringBuffer(length);
    for (int i = 0; i < (length - str.length()); i++) {
        temp.append(WHITE_SPACE);
    temp.append(str);
    return temp.toString();
} else {
...
StringalignRight(String str, int size, char padChar)
align Right
if (str == null) {
    return null;
int pads = size - str.length();
if (pads <= 0) {
    return str;
return alignRight(str, size, String.valueOf(padChar));
...
StringalignRight(String substring, int totalWidth, char fill)
Returns a string of the specified length where the substring is located to the right, padded with a character on the left.
if (substring.length() > totalWidth) {
    return substring.substring(0, totalWidth);
} else {
    return repeat("" + fill, totalWidth - substring.length()) + substring;
StringalignRight(String text, int length)
Right align a string by adding spaces on the left up to specified length.
StringBuffer result = new StringBuffer();
for (int i = 1; i <= (length - text.length()); i++) {
    result.append(" ");
result.append(text);
return result.toString();
StringalignRight(String val, char pad, int width)
align Right
if (val.length() > width) {
    val = val.substring(0, width - 1) + "*";
    return val;
while (val.length() < width)
    val = pad + val;
return val;