Why can't we just make a comparison between hashValue.toString() and argument md5 of the method? Why do we have to transform the contents of hashValue into HexString. Also, what is the use of the arguments in line 2 of the first code block?
for (byte b : hashValue) {
           String x = Integer.toHexString(0xFF & b);
           if (x.length() < 2) x = "0" + x;
           hexString.append(x);
       }
MessageDigest md = MessageDigest.getInstance("MD5");
     md.update(byteArrayOutputStream.toByteArray());
     byte[] hashValue = md.digest();

     StringBuffer hexString = new StringBuffer();

     for (byte b : hashValue) {
         String x = Integer.toHexString(0xFF & b);
         if (x.length() < 2) x = "0" + x;
         hexString.append(x);
     }
     return hexString.toString().equals(md5);
 }