Java Utililty Methods String Left Align

List of utility methods to do String Left Align

Description

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

Method

StringleftAlign(int totalWidth, String s)
left Align
return String.format("%1$-" + totalWidth + "s", s);
StringleftAlign(String s, int width)
left Align
String r = s;
int n = width - s.length();
for (int i = 0; i < n; i++) {
    r += ' ';
return r;
StringleftAlign(String text, int width)
Appends spaces until length of text is at least width.
return rightPad(text, width, ' ');
StringBuilderleftAlign(StringBuilder in, int len)
Left aligns some text in a StringBuilder N.B.
int sfx = len - in.length();
if (sfx <= 0) {
    return in;
if (sfx > SPACES_LEN) {
    sfx = SPACES_LEN;
in.append(SPACES.substring(0, sfx));
...