Class HexFormatExamples

java.lang.Object
net.jrodolfo.java_evolution.java17.HexFormatExamples

public class HexFormatExamples extends Object
Demonstrates HexFormat, introduced in Java 17.

Before Java 17, converting bytes to hexadecimal text and parsing hexadecimal text back into bytes often required custom utility code or an external library.

HexFormat solves this small but common problem with a standard API that supports parsing, formatting, delimiters, prefixes, and suffixes.

  • Constructor Details

    • HexFormatExamples

      public HexFormatExamples()
  • Method Details

    • toHex

      public String toHex(byte[] bytes)
      Converts bytes to lowercase hexadecimal text.
      Parameters:
      bytes - the bytes to format
      Returns:
      hexadecimal text
    • fromHex

      public byte[] fromHex(String hex)
      Parses hexadecimal text into bytes.
      Parameters:
      hex - hexadecimal text
      Returns:
      parsed bytes
    • toColonDelimitedHex

      public String toColonDelimitedHex(byte[] bytes)
      Formats bytes with a delimiter.
      Parameters:
      bytes - the bytes to format
      Returns:
      hexadecimal text separated with colons