Java String Pad Right rightPad(final String input, final int size)

Here you can find the source of rightPad(final String input, final int size)

Description

right Pad

License

Apache License

Declaration

public static String rightPad(final String input, final int size) 

Method Source Code

//package com.java2s;
/*// w w  w. j av  a  2  s. c om
 *     Copyright 2015-2017 Austin Keener & Michael Ritter & Florian Spie?
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static String rightPad(final String input, final int size) {
        int pads = size - input.length();
        if (pads <= 0)
            return input;
        StringBuilder out = new StringBuilder(input);
        for (int i = pads; i > 0; i--)
            out.append(' ');
        return out.toString();
    }
}

Related

  1. rightPad(byte[] bytes, int length, byte padByte)
  2. rightPad(final String str, final int size, final char padChar)
  3. rightPad(String _str, int _size, char _padChar)
  4. rightPad(String csIn, int nRequiredLength, char cFill)
  5. rightPad(String field, char padding, int width)