HexFormat.of() gives a reusable formatter that turns a byte array into a lowercase hex string with formatHex, and parses one back into bytes with parseHex, replacing the hand-rolled loops developers used to write.
byte[] data = {0x0A, (byte) 0xFF, 0x42};
HexFormat hex = HexFormat.of();
String encoded = hex.formatHex(data);
System.out.println("Encoded: " + encoded);
byte[] decoded = hex.parseHex(encoded);
System.out.println("Round trip equal: " + Arrays.equals(data, decoded));
Encoded: 0aff42
Round trip equal: true
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27