public static String toHexString(byte[] byteArray){
  if (byteArray != null && byteArray.length != 0) {
    StringBuilder builder=new StringBuilder(byteArray.length * 3);
    for (int i=0; i < byteArray.length; i++) {
      builder.append(String.format("%02X",0xFF & byteArray[i]));
      if (i < byteArray.length - 1) {
        builder.append(' ');
      }
    }
    return builder.toString();
  }
 else {
    return "--";
  }
}

public static String toHexString ( byte [ ] byteArray ) { if ( byteArray != null && byteArray . length != 0 ) { StringBuilder builder = new StringBuilder ( byteArray . length * 3 ) ; for ( int i = 0 ; i < byteArray . length ; i ++ ) { builder . append ( String . format ( "%02X" , 0xFF & byteArray [ i ] ) ) ; if ( i < byteArray . length - 1 ) { builder . append ( ' ' ) ; } } return builder . toString ( ) ; } else { return "--" ; } }
takes a byte array and returns it hex representation .
