Date/Time intermediate

HexFormat

Convert between hex strings and byte arrays with HexFormat.

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

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
Since JDK
17
Difficulty
intermediate
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.

Share 𝕏 🦋 in