Android Utililty Methods Byte Array Equal

List of utility methods to do Byte Array Equal

Description

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

Method

booleanconstantTimeAreEqual(byte[] a, byte[] b)
A constant time equals comparison - does not terminate early if test will fail.
if (a == b) {
    return true;
if (a == null || b == null) {
    return false;
if (a.length != b.length) {
    return false;
...
booleanequals(byte[] array1, byte[] array2)
equals
if ((array1 == null && array2 != null)
        || (array1 != null && array2 == null))
    return false;
else if (array1 != null && array2 != null) {
    if (array1.length != array2.length)
        return false;
    for (int i = array1.length; --i >= 0;)
        if (array1[i] != array2[i])
...
booleanequals(byte[] array1, byte[] array2, int length)
Checks if the beginnings of two byte arrays are equal.
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++) {
...
booleanequals(byte[] array1, byte[] array2, int length)
Checks if the beginnings of two byte arrays are equal.
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++) {
...
booleanequals(byte[] array1, byte[] array2, int length)
equals
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++) {
...
booleanequals(final byte[] pArrayA, final int pOffsetA, final byte[] pArrayB, final int pOffsetB, final int pLength)
equals
final int lastIndexA = pOffsetA + pLength;
if (lastIndexA > pArrayA.length) {
    throw new ArrayIndexOutOfBoundsException(pArrayA.length);
final int lastIndexB = pOffsetB + pLength;
if (lastIndexB > pArrayB.length) {
    throw new ArrayIndexOutOfBoundsException(pArrayB.length);
for (int a = pOffsetA, b = pOffsetB; a < lastIndexA; a++, b++) {
    if (pArrayA[a] != pArrayB[b]) {
        return false;
return true;
booleanequals(final byte[] pArrayA, final int pOffsetA, final byte[] pArrayB, final int pOffsetB, final int pLength)
equals
final int lastIndexA = pOffsetA + pLength;
if (lastIndexA > pArrayA.length) {
    throw new ArrayIndexOutOfBoundsException(pArrayA.length);
final int lastIndexB = pOffsetB + pLength;
if (lastIndexB > pArrayB.length) {
    throw new ArrayIndexOutOfBoundsException(pArrayB.length);
for (int a = pOffsetA, b = pOffsetB; a < lastIndexA; a++, b++) {
    if (pArrayA[a] != pArrayB[b]) {
        return false;
return true;
booleanisEqual(byte[] first, byte[] second)
is Equal
boolean out = first != null && second != null
        && first.length == second.length;
for (int i = 0; out && i < first.length; i++) {
    if (first[i] != second[i]) {
        out = false;
return out;
...
booleanequalByteArray(byte[] src, byte[] dst)
Compares this byte arrary to the specified object.
return equalByteArray(src, 0, src.length, dst, 0, dst.length);
booleanequalByteArray(byte[] src, int srcOffset, int srcLen, byte[] dst, int dstOffset, int dstLen)
equal Byte Array
if (compareByteArray(src, srcOffset, srcLen, dst, dstOffset, dstLen) == 0) {
    return true;
} else {
    return false;