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

StringbyteArrayToHexString(byte[] bytes, int pos, int len)
Converts a byte array to hex string.
StringBuilder sb = new StringBuilder(bytes.length * 2);
Formatter formatter = new Formatter(sb);
for (int i = pos; i < pos + len; ++i) {
    formatter.format("%02x", bytes[i]);
return sb.toString();
StringbytesToHexString(byte[] bytes)
bytes To Hex String
StringBuilder sb = new StringBuilder(bytes.length * 2);
Formatter formatter = new Formatter(sb);
for (byte b : bytes) {
    formatter.format("%02x", b);
formatter.close();
return sb.toString();
StringbyteToHex(final byte[] bytes)
byte To Hex
Formatter formatter = new Formatter();
for (byte b : bytes) {
    formatter.format("%02x", b);
String result = formatter.toString();
formatter.close();
return result;
StringbyteToHexWithPrefix(final byte[] data)
Convert bytes to hex + 0x in front.
return "0x" + byteToHex(data);
booleanchatting(String fmt, Object... args)
Formatted output
Formatter f = new Formatter(System.out);
f.format(fmt, args);
return true;
StringconvertRGBDecToHex(String decimal)
Convert rgb dec to hex.
String returnValue = null;
Formatter formatter = null;
formatter = new Formatter();
returnValue = "#" + formatter
        .format("%02x%02x%02x", Integer.parseInt(decimal.substring(0, 3)),
                Integer.parseInt(decimal.substring(3, 6)), Integer.parseInt(decimal.substring(6, 9)))
        .toString();
return returnValue;
...
StringconvertTimeToString(double d, String timeFormat)
Converts time to string.
StringBuilder sb = new StringBuilder();
try (Formatter formatter = new Formatter(sb, Locale.US)) {
    double s = d % 60;
    int h = (int) (d / 3600);
    int m = ((int) (d / 60)) % 60;
    formatter.format(timeFormat, h, m, s);
return sb.toString();
...
StringconvertToMillions(double tmp)
convert To Millions
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb);
formatter.format("%12.6f mio", tmp / 1000. / 1000.);
formatter.close();
return sb.toString();
StringcreateHexadecimalString(byte[] data)
Creates the hexadecimal string encoding specified data.
StringBuilder sb = new StringBuilder(data.length * 2);
Formatter formatter = new Formatter(sb);
for (byte b : data) {
    formatter.format("%02x", b);
formatter.close();
return sb.toString();
StringdigestToString(byte[] input)
Creates a String from a MessageDigest result.
Formatter formatter = new Formatter();
for (byte b : input) {
    formatter.format("%02x", b);
return formatter.toString();