3

I use Java8 and I wonder if Java8 has an equivalent method to org.apache.commons.codec.Hex.encodeHexString

Thanks!

Shvalb
  • 1,835
  • 2
  • 30
  • 60

2 Answers2

1

Integer.toHexString(int) is available. As is BigInteger.toString(int radix). Both can encode to hex.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

It is hard to tell what you really need without seeing example of input and expected output, but based on your comment under @Elliott's answer:

Hex.encodeHexString() - input is a byte[] and output is String.

you may be looking for HexBinaryAdapter class and its

  • String marshal(byte[] bytes)
  • byte[] unmarshal(String s)

methods (although they are non-static so you will need instance of this adapter).


They internally invoke these static methods:

  • DatatypeConverter.printHexBinary(bytes)
  • DatatypeConverter.parseHexBinary(s)

So you may want to take a look at DatatypeConverter class.

Community
  • 1
  • 1
Pshemo
  • 122,468
  • 25
  • 185
  • 269