I'm trying to use org.apache.commons.codec.binary.Hex to encode and decode a String value:
e.g.:
Hex.encodeHex("10".getBytes()).toString();
However, this is not giving me a hexadecimal output, but outputs similar to this:
[C@596d444a
Any ideas why this is happening?
Yes - the call to
encodeHex()
returns a char array (char[]
) and you're just callingtoString
on that. Use the String(char[]) constructor instead:(I would strongly encourage you not to use the parameterless
String.getBytes()
method, by the way, which uses the platform default encoding. It's a constant source of subtle errors.)