Java Encode and Decode Hex String using Apache Commons Codec In this Java tutorial we learn how to use Hex class of Apache Commons Codec library to encode byte[] array to hexadecimal String and decode hexadecimal String to byte[] array.