Java String Pad Right rightPad(StringBuilder pStringBuilder, int pLength, char pChar)

Here you can find the source of rightPad(StringBuilder pStringBuilder, int pLength, char pChar)

Description

Similar to the Oracle rpad command.

License

Open Source License

Parameter

Parameter Description
pStringBuilder The StringBuffer object to pad.
pLength The length to pad to.
pChar The character to pad with.

Return

StringBuffer the chomped string.

Declaration

public static StringBuilder rightPad(StringBuilder pStringBuilder, int pLength, char pChar) 

Method Source Code

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

public class Main {
    /**/*ww w  .  j  a  v a  2  s  .  c o  m*/
     * Similar to the Oracle rpad command. Right pads a string.
     *
     * @param pStringBuilder The StringBuffer object to pad.
     * @param pLength The length to pad to.
     * @param pChar The character to pad with.
     * @return StringBuffer the chomped string.
     */
    public static StringBuilder rightPad(StringBuilder pStringBuilder, int pLength, char pChar) {
        while (pStringBuilder.length() < pLength) {
            pStringBuilder.append(pChar);
        }

        return pStringBuilder;
    }

    /**
     * Similar to the Oracle rpad command. Right pads a string.
     *
     * @param pString The String object to pad.
     * @param pLength The length to pad to.
     * @param pChar The character to pad with.
     * @return String the padded string.
     */
    public static String rightPad(String pString, int pLength, char pChar) {
        return rightPad(new StringBuilder(pString), pLength, pChar).toString();
    }

    /**
     * Similar to the Oracle rpad command. Right pads a string.
     *
     * @param pString The String object to pad.
     * @param pLength The length to pad to.
     * @return String the padded string.
     */
    public static String rightPad(String pString, int pLength) {
        return rightPad(new StringBuilder(pString), pLength, ' ').toString();
    }
}

Related

  1. rightPad(String targetStr, char appendChar, int length)
  2. rightPad(String toPad, int totalLength)
  3. rightPad(String value, int length)
  4. rightPad(String value, int makeLength, char paddingCharacter)
  5. rightPad(String value, int tamanho, String pad)
  6. rightPadded(String src, int len)
  7. rightPaddedBaseString(String bases, int length)
  8. rightPaddedString(String string, int length, char paddingChar)
  9. rightPadding(int id, int value)