◐ Shell
clean mode source ↗

HexFormat

Code Comparison

// Pad to 2 digits, uppercase
String hex = String.format(
    "%02X", byteValue);
// Parse hex string
int val = Integer.parseInt(
    "FF", 16);
var hex = HexFormat.of()
    .withUpperCase();
String s = hex.toHexDigits(
    byteValue);
byte[] bytes =
    hex.parseHex("48656C6C6F");

Why the modern way wins

📐

Bidirectional

Convert bytes→hex and hex→bytes with one API.

🔧

Configurable

Delimiters, prefix, suffix, upper/lower case.

📦

Array support

Encode/decode entire byte arrays at once.

Old Approach

Manual Hex Conversion

Modern Approach

HexFormat

JDK Support

HexFormat

Available

Widely available since JDK 17 LTS (Sept 2021)

How it works

HexFormat provides bidirectional hex encoding/decoding for bytes, ints, and arrays. Configure delimiters, prefix, suffix, and case. No more manual formatting or parsing.

Related Documentation

Proof