Java String Pad Right rightPad(String string, int length)

Here you can find the source of rightPad(String string, int length)

Description

right Pad

License

Open Source License

Declaration

public static String rightPad(String string, int length) 

Method Source Code

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

public class Main {
    public static String rightPad(String string, int length) {
        return rightPad(string, length, ' ');
    }//from  www .  j  a  va2  s  .co  m

    public static String rightPad(String string, int length, char ch) {
        if (string == null || string.length() >= length)
            return string;
        StringBuffer sb = new StringBuffer(string);
        for (int i = (string.length() - 1); i < length - 1; i++)
            sb.append(ch);
        return sb.toString();
    }
}

Related

  1. rightPad(String str, int size, char padChar)
  2. rightPad(String str, int size, String padStr)
  3. rightPad(String str, int width)
  4. rightPad(String str, int width, char padding)
  5. rightPad(String str, String pad, int len)
  6. rightPad(String strInput, int intLength)
  7. rightPad(String targetStr, char appendChar, int length)
  8. rightPad(String toPad, int totalLength)
  9. rightPad(String value, int length)