Java String Pad Right rightPad(String toPad, int totalLength)

Here you can find the source of rightPad(String toPad, int totalLength)

Description

right Pad

License

Open Source License

Declaration

public static String rightPad(String toPad, int totalLength) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String rightPad(String toPad, int totalLength) {
        if (toPad == null)
            return null;

        if (toPad.length() >= totalLength) {
            return toPad.substring(0, totalLength);
        }//  w  w w .  j a  v a  2 s  .c om

        StringBuffer buf = new StringBuffer(toPad);
        while (buf.length() < totalLength) {
            buf.append(" ");
        }
        return buf.toString();

    }
}

Related

  1. rightPad(String str, int width, char padding)
  2. rightPad(String str, String pad, int len)
  3. rightPad(String string, int length)
  4. rightPad(String strInput, int intLength)
  5. rightPad(String targetStr, char appendChar, int length)
  6. rightPad(String value, int length)
  7. rightPad(String value, int makeLength, char paddingCharacter)
  8. rightPad(String value, int tamanho, String pad)
  9. rightPad(StringBuilder pStringBuilder, int pLength, char pChar)