Java String Pad Right rightPad(String strInput, int intLength)

Here you can find the source of rightPad(String strInput, int intLength)

Description

Pad " " to String right side.

License

Open Source License

Parameter

Parameter Description
strInput string to be right padded
intLength right pad the input string to intLength( in bytes )

Return

the string after right padding

Declaration

public static String rightPad(String strInput, int intLength) 

Method Source Code

//package com.java2s;
/*/*from w  w  w . ja v a2  s  .c  o m*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

public class Main {
    /**
     * Pad " " to String right side.
     *
     * @param strInput  string to be right padded
     * @param intLength right pad the input string to intLength( in bytes )
     * @return the string after right padding
     */
    public static String rightPad(String strInput, int intLength) {
        byte[] byteResult = new byte[intLength];
        byte[] byteInput = strInput.getBytes();
        System.arraycopy(byteInput, 0, byteResult, 0, byteInput.length);
        for (int i = byteInput.length; i < intLength; i++) {
            byteResult[i] = ' ';
        }
        return new String(byteResult);
    }
}

Related

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