Java String Pad Right rightPad(String field, char padding, int width)

Here you can find the source of rightPad(String field, char padding, int width)

Description

right Pad

License

Open Source License

Declaration

public static String rightPad(String field, char padding, int width) 

Method Source Code

//package com.java2s;

public class Main {
    public static String rightPad(String field, char padding, int width) {
        String answer;/*from www.ja v  a  2  s.c  o  m*/
        if (field.length() < width) {
            answer = field + fill(padding, width - field.length());
        } else {
            answer = field;
        }
        return answer;
    }

    public static String fill(final char c, final int n) {
        StringBuffer answer = new StringBuffer(n);
        fill(answer, c, n);
        return answer.toString();
    }

    public static void fill(StringBuffer buf, final char c, final int n) {
        for (int i = 0; i < n; i++) {
            buf.append(c);
        }
    }
}

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 _str, int _size, char _padChar)
  5. rightPad(String csIn, int nRequiredLength, char cFill)
  6. rightPad(String in, char padding, int length)
  7. rightPad(String in, int len, String pad)
  8. rightPad(String input, char padding, int length)
  9. rightPad(String input, int length, char pad)