Here you can find the source of toHex(byte[] data)
static String toHex(byte[] data)
//package com.java2s; import java.util.Formatter; public class Main { static String toHex(byte[] data) { if (data == null || data.length == 0) return null; StringBuilder stringBuilder = new StringBuilder(data.length * 2); Formatter formatter = null; try {//from w w w . j a v a2 s.c om formatter = new Formatter(stringBuilder); for (byte b : data) { formatter.format("%02x", b); } return "0x" + stringBuilder.toString(); } finally { if (formatter != null) formatter.close(); } } }