> I need to know if one byte array is equal to another. Is there any method to compare two byte arrays?
byte[] barray1 = new byte[10];
byte[] barray2 = new byte[10];
//fill the arrays
boolean arraysEqual = java.util.Arrays.equals(barray1, barray2);
> I know one way by comparing byte to byte, but if arrays are
> big, it's very slow.
>
> Thanks.
How else could you compare the 2 arrays? I'm sure that this Sun implementation has been tuned for speed
If you know nothing about the arrays, then it is possible that they are identical except for one entry. So it follows that any algorithm to compare them for equality must be prepared to look at every entry in the array. No good moaning that it's slow, it's as fast as possible.
But if you DO know something about the arrays, perhaps that the data in them is structured in a certain way, then it might be possible to write more complicated but faster comparison algorithms.