In the definition of equals() in an object class, use the following:
java.util.Arrays.equals(bs1, bs2)
You can also check if they are the same array (instance). Although this method may well do it.
For example (and make some assumptions about your class that contains arrays):
public boolean equals(Object obj) { if(this == obj) return true; if(!(obj instanceof MyObject)) // covers case where obj null, too. return false; return Arrays.equals(this.bytes, ((MyObject)obj).bytes); }
If there are other fields in your class, your equals() should consider them as well.
(It might be better to answer the question if you can provide additional information about what data is stored in arrays.)
source share