Original URL: http://amanda.blog.51cto.com/7238262/1215118
Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://amanda.blog.51cto.com/7238262/1215118
Two comparisons between arrays (compares the contents of two arrays):
Method One:
Directly call the Java API for comparison
1: Convert byte[] Array to String (premise: byte[] array B1 b2 not empty)
2: Call Equals () method to compare, return true for equality, otherwise return false
1:
String S1 = arrays.tostring (byte[] B1);
String s2 = arrays.tostring (byte[] B2);
2:
S1.equals (S2)
Method Two:
1: Make sure two arrays are not empty, otherwise, return false
2: Compare length first, return False if length is not equal
3: Under the premise of equal length, take out the array subscript content separately, loop compare, return False when different, and exit
public static Boolean Comperebytearray (Byte[] B1, byte[] b2) {
1:
if (B1.length = = 0 | | b2.length = = 0) {
return false;
}
2:
if (b1.length! = b2.length) {
return false;
}
3:
Boolean isequal = true;
for (int i = 0; i < b1.length && i < b2.length; i++) {
if (b1[i]! = B2[i]) {
System.out.println ("different");
IsEqual = false;
Break
}
}
return isequal;
}
This article is from the "Intercept string" blog, so be sure to keep this source http://amanda.blog.51cto.com/7238262/1215118
"Go" byte[] Array comparison (content comparison)--good