Java Utililty Methods Formatter Usage

List of utility methods to do Formatter Usage

Description

The list of methods to do Formatter Usage are organized into topic(s).

Method

StringalterationValueToString(double value)
Format percentage.
if (0.0 < value && value <= 0.01) {
    return "<1%";
Formatter f = new Formatter();
f.format("%.0f", value * 100.0);
return f.out().toString() + "%";
Formatterappend(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision)
Handles the common Formattable operations of truncate-pad-append, with no ellipsis on precision overflow, and padding width underflow with spaces.
return append(seq, formatter, flags, width, precision, ' ', null);
StringasFormattedStr(String format, String eol, Object... objects)
as Formatted Str
Formatter f = new Formatter();
String s = f.format(format + "%s", objects, eol).toString();
f.close();
return s;
voidassertion(final boolean test, final String fmt, final Object... params)
assertion
if (test) {
    return;
final Formatter f = new Formatter();
throw new RuntimeException(f.format(fmt, params).toString());
Stringbyte2Mac(final byte[] m)
byte Mac
final StringBuilder result = new StringBuilder(17);
final Formatter formatter = new Formatter(result);
formatter.format("%02x:%02x:%02x:%02x:%02x:%02x", m[0], m[1], m[2], m[3], m[4], m[5]);
formatter.close();
return result.toString();
StringbyteArray2Hex(byte[] hash)
byte Array Hex
Formatter formatter = new Formatter();
for (byte b : hash) {
    formatter.format("%02x", b);
return formatter.toString();
StringbyteArray2Hex(final byte[] hash)
Converts an input byte array to a hex encoded String.
Formatter formatter = new Formatter();
for (byte b : hash) {
    formatter.format("%02x", b);
return formatter.toString();
StringbyteArray2HexString(byte[] buf)
byte Array Hex String
return byteArray2HexString(buf, ',');
StringbyteArrayToHex(final byte[] hash)
Get the hex string representation of a given byte array
String result;
Formatter formatter = new Formatter();
try {
    for (byte b : hash) {
        formatter.format("%02x", b);
    result = formatter.toString();
} catch (Exception lEx) {
...
StringbyteArrayToHexString(byte[] bytes)
byte Array To Hex String
@SuppressWarnings("resource")
Formatter fmt = new Formatter(new StringBuilder(bytes.length * 2));
for (byte b : bytes) {
    fmt.format("%02x", b);
return fmt.toString();