Java String Pad Right rightPad(String _str, int _size, char _padChar)

Here you can find the source of rightPad(String _str, int _size, char _padChar)

Description

right Pad

License

Open Source License

Declaration

public static String rightPad(String _str, int _size, char _padChar) 

Method Source Code

//package com.java2s;

public class Main {

    public static String rightPad(String _str, int _size, char _padChar) {
        if (_str == null) {
            return null;
        }//from w  ww .j a v  a 2  s .  c om
        int pads = _size - _str.length();
        if (pads <= 0) {
            return _str; // returns original String when possible
        }
        return _str.concat(padding(pads, _padChar));
    }

    private static String padding(int _repeat, char _padChar) {
        String value = "";
        String padStr = String.valueOf(_padChar);
        if (_repeat > 0) {
            for (int i = 0; i < _repeat; i++) {
                value = value.concat(padStr);
            }
        }
        return value;
    }
}

Related

  1. rightPad(byte[] bytes, int length, byte padByte)
  2. rightPad(final String input, final int size)
  3. rightPad(final String str, final int size, final char padChar)
  4. rightPad(String csIn, int nRequiredLength, char cFill)
  5. rightPad(String field, char padding, int width)
  6. rightPad(String in, char padding, int length)
  7. rightPad(String in, int len, String pad)