static String bytesToHex(final byte[] bytes) { return IntStream.range(0, bytes.length) .mapToObj(i->String.format("%02x", bytes[i]&0xff)) .collect(joining()); }
although the following may be more effective:
static String bytesToHex(final byte[] bytes) { return IntStream.range(0, bytes.length) .collect(StringBuilder::new, (sb,i)->new Formatter(sb).format("%02x", bytes[i]&0xff), StringBuilder::append).toString(); }
Both support parallel processing.
source share