Java Integer to intToStringBuffer(final int param, final int len)

Here you can find the source of intToStringBuffer(final int param, final int len)

Description

convert an integer to a StringBuffer (left padding).

License

Open Source License

Parameter

Parameter Description
param An integer to convert
len The string length

Return

a string representation

Declaration

public static StringBuffer intToStringBuffer(final int param, final int len) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .  j av a 2  s. co  m
 * Utility.java
 *
 * HomePage :  http://www.codeproject.com/csharp/TraceTool.asp
 * Download :  http://sourceforge.net/projects/tracetool/
 * See License.txt for license information
 *
 * Author : Thierry Parent
 * Version : 12.3
 *
 * Provide some utility functions
 */

public class Main {
    /**
     * convert an integer to a StringBuffer (left padding).
     * @param param  An integer to convert
     * @param len The string length
     * @return a string representation
     */
    public static StringBuffer intToStringBuffer(final int param, final int len) {
        StringBuffer temp = new StringBuffer(Integer.toString(param));
        leftPadding(temp, len, ' ');
        return temp;
    }

    /**
     * Left Pad Stringbuffer with special char
     * @param strBuf Target buffer
     * @param bufLen Buffer length
     * @param fill Char to fill
     * @return a padded StringBuffer
     */
    public static StringBuffer leftPadding(final StringBuffer strBuf, final int bufLen, final char fill) {
        while (strBuf.length() < bufLen)
            strBuf.insert(0, fill);
        return strBuf;
    }
}

Related

  1. intToRoman(int value)
  2. intToScaleString(final int number, final int scale)
  3. intToShort(final int value)
  4. intToSlider(final int min, final int max, final int value)
  5. intToSortableBytes(int value, byte[] result, int offset)
  6. intToStringWithZeroFill(int intValue, int width)
  7. intToTime(int time)
  8. intToTime(int value)
  9. intToTriplePlace(int i)