public static boolean equals(byte[] array1, byte[] array2, int length) {
    if (length < 0) {
      throw new IllegalArgumentException();
    }

    if (array1 == array2) {
      return true;
    }
    if (array1 == null || array2 == null || array1.length < length || array2.length < length) {
      return false;
    }
    for (int i = 0; i < length; i++) {
      if (array1[i] != array2[i]) {
        return false;
      }
    }
    return true;
  }
Checks if the beginnings of two byte arrays are equal.

@param array1 the first byte array
@param array2 the second byte array
@param length the number of bytes to check
@return true if they're equal, false otherwise
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/ArrayUtils.java