Java Utililty Methods Zero Format

List of utility methods to do Zero Format

Description

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

Method

StringzeroFill(int value, int fieldWidth)
Returns a zero-filled string.
StringBuilder buf = new StringBuilder();
buf.append(value);
while (buf.length() < fieldWidth) {
    buf.insert(0, ZERO);
return buf.toString();
Stringzerofill(int x, int desiredWidth)
fills the left side of a number with zeros
e.g.
StringBuffer buf = new StringBuffer();
if (x < 0) {
    buf.append("-");
    desiredWidth--;
    x = -x;
while (desiredWidth > 7) {
    buf.append("0");
...
StringzeroFillString(String originalString, int numZeros)
zero Fill String
if (originalString.length() < numZeros) {
    int zerosToAdd = numZeros - originalString.length();
    for (int i = 0; i < zerosToAdd; i++) {
        originalString = "0" + originalString;
return originalString;
StringzeroFormat(Integer source)
zero Format
String stringSource = String.valueOf(source);
if (stringSource.length() >= 3)
    return source + "";
return String.format("%03d", source);
StringzeroFormattedStr(int number, int length)
zero Formatted Str
return zeroFormattedStr((long) number, length);
intzeroIfNull(Integer i)
converts an Integer to an int, mapping null to 0 and mapping Integer(0) to 0 also.
final int result = (i == null) ? 0 : i;
assert !(i == null) || (result == 0);
assert !(i != null) || (result == i);
return result;
intzeroIfNull(Integer i)
zero If Null
return i != null ? i.intValue() : 0;
intzeroIfNullStrict(Integer i)
converts an Integer to an int, mapping null to 0.
final int result;
if (i == null) {
    result = 0;
} else {
    result = i;
    if (result == 0) {
        throw new IllegalArgumentException("langutils.integer.not.allowed.exception");
assert !(i == null) || (result == 0);
assert !((i != null) && (i != 0)) || (result == i);
return result;
byte[]zeroInterval(byte[] x, int start, int end)
zero Interval
final byte[] result = x.clone();
for (int i = start; i < end; i++)
    result[i] = (byte) 0;
return result;
longzeroLowerBits(long bits, int nBits)
Zeroes the lower n bits of a bitstring.
long invMask = (1L << nBits) - 1L;
long mask = ~invMask;
long zeroed = bits & mask;
return zeroed;