Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
IBM : developerWorks : Java : Education - online courses
Java Collections Framework
Download tutorial zip fileView letter-sized PDF fileView A4-sized PDF fileE-mail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPreviousNext
6. Algorithm support
  


Checking equality page 4 of 6


While the MessageDigest class always provided an isEqual() method to compare two byte arrays, it never felt right to use it to compare byte arrays unless they were from message digests. Now, with the help of the Arrays class, you can check for equality of any array of primitive or object type. Two arrays are equal if they contain the same elements in the same order. Checking for equality with arrays of objects relies on the equals() method of each object to check for equality.

byte array1[] = ...;
byte array2[] = ...;
if (Arrays.equals(array1, array2) {
  // They're equal
}

Main menuSection menuGive feedback on this tutorialPreviousNext
PrivacyLegalContact