private static final char[] HEX_CHAR = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
public static String toHexString1(byte[] bytes) {
char[] buff = new char[bytes.length<<1];
int index=0;
for(byte b:bytes) {
buff[index++] = HEX_CHAR[b>>>4&0xf];
buff[index++] = HEX_CHAR[b&0xf];
}
return new String(buff);
}
public static String toHexString2(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for(byte b:bytes) {
String buf = Integer.toHexString(b&0xff);
if (buf.length() < 2) {
sb.append(0);
}
sb.append(buf);
}
return sb.toString();
}
经过检测toHexString1是toHexString2的10倍效率