Java Utililty Methods Integer Format

List of utility methods to do Integer Format

Description

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

Method

StringformatInteger(Integer value)
Formats an integer attribute.
if (value != null) {
    return value.toString();
return null;
StringformatIntegerBase2WithLeadingZeros(long x, int length)
format Integer Base With Leading Zeros
return pad(Long.toBinaryString(x), length, 1);
StringformatIntegerWithLeadingZeros(long x, int radix, int length)
format Integer With Leading Zeros
return radix == 2 ? formatIntegerBase2WithLeadingZeros(x, length)
        : radix == 8 ? formatIntegerBase8WithLeadingZeros(x, length)
                : radix == 16 ? formatIntegerBase16WithLeadingZeros(x, length)
                        : formatIntegerBaseSomeWithLeadingZeros(x, radix, length);
StringformatIntents(String[] intents)
format Intents
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String intent : intents) {
    if (first) {
        first = false;
    } else {
        sb.append(' ');
    sb.append(intent);
return sb.toString();
StringformatInterval(long interval)
Returns human readable representation of interval value in days, hours etc.
long days = interval / (24 * 60 * 60);
interval -= days * 24 * 60 * 60;
long hours = interval / (60 * 60);
interval -= hours * 60 * 60;
long minutes = interval / 60;
interval -= minutes * 60;
long seconds = interval;
StringBuffer buff = new StringBuffer();
...
StringformatIntoHHMMSS(int secsIn)
format Into HHMMSS
int hours = secsIn / 3600, remainder = secsIn % 3600, minutes = remainder / 60, seconds = remainder % 60;
return ((hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + ":"
        + (seconds < 10 ? "0" : "") + seconds);
StringformatIntoHHMMSS(long l)
format Into HHMMSS
long hours = l / 3600, remainder = l % 3600, minutes = remainder / 60, seconds = remainder % 60;
return ((hours < 10 ? "0" : "") + hours + "h" + (minutes < 10 ? "0" : "") + minutes + "m"
        + (seconds < 10 ? "0" : "") + seconds + "s");
StringformatIntOrLong(long v)
format Int Or Long
if (v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE)
    return v + "";
return v + "L";
StringformatInts(int[] vals)
Formats an array of ints.
String res = "";
if (vals == null)
    res = "(null)";
else {
    res = "[";
    for (int ii = 0; ii < vals.length; ii++) {
        if (ii > 0)
            res += " ";
...
StringformatIntWithPadding(int value, int length, char pad)
format Int With Padding
String valueStr = value + "";
int diff = length - valueStr.length();
StringBuilder strBuilder = new StringBuilder();
if (diff > 0) {
    while (diff > 0) {
        diff--;
        strBuilder.append(pad);
    strBuilder.append(valueStr);
    valueStr = strBuilder.toString();
return valueStr;