Java Utililty Methods Integer Pad Zero

List of utility methods to do Integer Pad Zero

Description

The list of methods to do Integer Pad Zero are organized into topic(s).

Method

byte[]zeroPad(final byte[] data, final int blockSize)
zero Pad
if (data == null) {
    throw new IllegalArgumentException("Please provide some data to pad");
if (blockSize <= 0 || blockSize % Byte.SIZE != 0) {
    throw new IllegalArgumentException("Blocksize must be a possitive integer N where N % 8 = 0");
final int blockSizeBytes = blockSize / Byte.SIZE;
if (data.length % blockSizeBytes == 0) {
...
StringzeroPad(final int amount, final String in)
Pad a string out (yes I know apache commons can do this but it's used by GWT).
final int left = amount - in.length();
final StringBuilder out = new StringBuilder();
for (int i = 0; i < left; i++) {
    out.append("0");
out.append(in);
return out.toString();
byte[]zeroPad(final int length, final byte[] bytes)
zero Pad
final byte[] padded = new byte[length];
System.arraycopy(bytes, 0, padded, 0, bytes.length);
return padded;
Stringzeropad(final int num, final int size)
Method zeropad
final String value = Integer.toString(num);
if (value.length() >= size) {
    return value;
final StringBuffer buf = new StringBuffer(size);
for (int i = 0; i++ < (size - value.length()); buf.append('0')) {
    ;
buf.append(value);
return buf.toString();
StringzeroPad(int i, int len)
Zero Pad an int
String s = Integer.toString(i);
if (s.length() > len) {
    return s.substring(0, len);
} else if (s.length() < len) {
    return "000000000000000000000000000".substring(0, len - s.length()) + s;
} else {
    return s;
StringzeroPad(int n, int base, int width)
Zero-pad an integer.
final String s;
switch (base) {
case 10:
    s = Integer.toString(n);
    break;
case 16:
    s = Integer.toHexString(n).toUpperCase();
    break;
...
StringzeroPad(int n, int len)

Return a padded string with leading zeros.

String s = n + "";
for (int i = len - s.length(); i > 0; i--) {
    s = '0' + s;
return s;
StringzeroPad(int number, int places)
Pads a number with leading zeroes and returns it as a string.
String zeroes = "000000000000000";
String n = Integer.toString(number);
if (n.length() >= places) {
    return n;
return zeroes.substring(0, places - n.length()) + n;
StringZeroPad(int number, int width)
Zero Pad
StringBuffer result = new StringBuffer("");
for (int i = 0; i < width - Integer.toString(number).length(); i++)
    result.append("0");
result.append(Integer.toString(number));
return result.toString();
StringzeroPad(int value, int padding)
zero Pad
StringBuilder b = new StringBuilder();
b.append(value);
while (b.length() < padding) {
    b.insert(0, "0");
return b.toString();