Java Array Compare areEqual(byte[] a, byte[] b)

Here you can find the source of areEqual(byte[] a, byte[] b)

Description

Returns true if the two designated byte arrays are (a) non-null, (b) of the same length, and (c) contain the same values.

License

Open Source License

Parameter

Parameter Description
a the first byte array.
b the second byte array.

Return

true if the two designated arrays contain the same values. Returns false otherwise.

Declaration

public static boolean areEqual(byte[] a, byte[] b) 

Method Source Code

//package com.java2s;
// under the terms of the GNU General Public License as published by the Free

public class Main {
    /**//from w w  w. j  av  a2  s.  c o  m
     * <p>Returns <code>true</code> if the two designated byte arrays are
     * (a) non-null, (b) of the same length, and (c) contain the same values.</p>
     *
     * @param a the first byte array.
     * @param b the second byte array.
     * @return <code>true</code> if the two designated arrays contain the same
     * values. Returns <code>false</code> otherwise.
     */
    public static boolean areEqual(byte[] a, byte[] b) {
        if (a == null || b == null) {
            return false;
        }
        int aLength = a.length;
        if (aLength != b.length) {
            return false;
        }
        for (int i = 0; i < aLength; i++) {
            if (a[i] != b[i]) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. areEqual(byte[] a, byte[] b)
  2. areEqual(byte[] a, byte[] b)
  3. areEqual(byte[] a, byte[] b)
  4. areEqual(byte[] array1, byte[] array2)
  5. AreEqual(double[] vector1, double[] vector2)
  6. areEqual(final byte[] a, final byte[] b)
  7. areEqualBytes(byte[] b1, byte[] b2)