Android Utililty Methods Byte Array Compare

List of utility methods to do Byte Array Compare

Description

The list of methods to do Byte Array Compare are organized into topic(s).

Method

intfindWhereDiffer(byte[] bytes1, byte[] bytes2, int limit)
find Where Differ
for (int i = 0; i < limit; i++) {
    if (bytes1[i] != bytes2[i])
        return i;
return -1;
booleancompare(byte[] a, byte[] b)
Compare tow bytearrays.
if (a == null || b == null) {
    return a == b;
if (a.length != b.length) {
    return false;
for (int i = 0; i < a.length; i++) {
    if (a[i] != b[i]) {
...
booleancompare(byte[] a, int a_pos, byte[] b, int b_pos, int length)
Compare parts of bytearrays.
if (a == null || b == null) {
    return length == 0;
if ((a.length < a_pos + length) || (b.length < b_pos + length)) {
    return false;
for (int i = 0; i < length; i++) {
    if (a[a_pos + i] != b[b_pos + i]) {
...
booleancompare(byte[] as, byte[] bs)
compare
boolean result = true;
int len = as.length;
if (len != bs.length) {
    return false;
for (int i = 0; i < len; i++) {
    if (as[i] != bs[i]) {
        result = false;
...
intcompareByteArray(byte[] src, byte[] dst)
compare Byte Array
return compareByteArray(src, 0, src.length, dst, 0, dst.length);
intcompareByteArray(byte[] src, int srcOffset, byte[] dst, int dstOffset, int length)
compare Byte Array
return compareByteArray(src, srcOffset, length, dst, dstOffset,
        length);
intcompareByteArray(byte[] src, int srcOffset, int srcLen, byte[] dst, int dstOffset, int dstLen)
Compares two byte array lexicographically..
char c1, c2;
if (src == null || srcOffset < 0 || srcLen < 0) {
    return Integer.MIN_VALUE;
if (dst == null || dstOffset < 0 || dstLen < 0) {
    return Integer.MIN_VALUE;
int n = Math.min(srcLen, dstLen);
...
intcompareNotNull(byte[] data1, byte[] data2)
Compare the contents of two byte arrays.
int len = Math.min(data1.length, data2.length);
for (int i = 0; i < len; i++) {
    byte b = data1[i];
    byte b2 = data2[i];
    if (b != b2) {
        return b > b2 ? 1 : -1;
int c = data1.length - data2.length;
return c == 0 ? 0 : (c < 0 ? -1 : 1);
booleancompareSecure(byte[] test, byte[] good)
Compare two byte arrays.
if ((test == null) || (good == null)) {
    return (test == null) && (good == null);
if (test.length != good.length) {
    return false;
if (test.length == 0) {
    return true;
...
intcompareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2)
compare To
int end1 = offset1 + length1;
int end2 = offset2 + length2;
for (int i = offset1, j = offset2; i < end1 && j < end2; i++, j++) {
    int a = (buffer1[i] & 0xff);
    int b = (buffer2[j] & 0xff);
    if (a != b) {
        return a - b;
return length1 - length2;