Java String Pad Right rightPad(String input, char padding, int length)

Here you can find the source of rightPad(String input, char padding, int length)

Description

right Pad

License

LGPL

Declaration

public static String rightPad(String input, char padding, int length) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static String rightPad(String input, char padding, int length) {
        if (nullOrEmpty(input))
            input = "";
        if (input.length() >= length)
            return input;
        String padString = createPad(padding, length - input.length());
        return input.concat(padString);
    }//from   w ww .  j  av a2  s. co  m

    public static boolean nullOrEmpty(String s) {
        return (s == null) ? true : "".equals(s.trim());
    }

    public static String createPad(char padding, int length) {
        StringBuilder out = new StringBuilder();
        for (int repeat = 0; repeat < length; repeat++)
            out.append(padding);
        return out.toString();
    }

    public static String trim(String s) {
        return emptyIfNull(s).trim();
    }

    public static String emptyIfNull(String s) {
        return (s == null) ? "" : s;
    }
}

Related

  1. rightPad(String _str, int _size, char _padChar)
  2. rightPad(String csIn, int nRequiredLength, char cFill)
  3. rightPad(String field, char padding, int width)
  4. rightPad(String in, char padding, int length)
  5. rightPad(String in, int len, String pad)
  6. rightPad(String input, int length, char pad)
  7. rightPad(String inStr, int length, char paddingChar)
  8. rightPad(String original, int length, char padChar)
  9. rightPad(String originalText, int length, char fillChar)