Java Array Compare arrayCompare(byte[] a, byte[] a2)

Here you can find the source of arrayCompare(byte[] a, byte[] a2)

Description

Returns true if the two specified arrays of bytes are equal to one another.

License

Open Source License

Parameter

Parameter Description
a one array to be tested for equality
a2 the other array to be tested for equality

Return

true if the two arrays are equal

Declaration

public static boolean arrayCompare(byte[] a, byte[] a2) 

Method Source Code

//package com.java2s;
/*//from  ww w .  j  a  v a  2 s  .  c o  m
 * Util - Some useful small methods for NFCIPConnection 
 * 
 * Copyright (C) 2009  Fran?ois Kooman <F.Kooman@student.science.ru.nl>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

public class Main {
    /**
     * Returns <tt>true</tt> if the two specified arrays of bytes are
     * <i>equal</i> to one another. Two arrays are considered equal if both
     * arrays contain the same number of elements, and all corresponding pairs
     * of elements in the two arrays are equal. In other words, two arrays are
     * equal if they contain the same elements in the same order. Also, two
     * array references are considered equal if both are <tt>null</tt>.
     * <p>
     * 
     * @param a
     *            one array to be tested for equality
     * @param a2
     *            the other array to be tested for equality
     * @return <tt>true</tt> if the two arrays are equal
     */
    public static boolean arrayCompare(byte[] a, byte[] a2) {
        if (a == a2)
            return true;
        if (a == null || a2 == null)
            return false;

        int length = a.length;
        if (a2.length != length)
            return false;

        for (int i = 0; i < length; i++)
            if (a[i] != a2[i])
                return false;

        return true;
    }
}

Related

  1. areEqual(final byte[] a, final byte[] b)
  2. areEqualBytes(byte[] b1, byte[] b2)
  3. areEqualPropPaths(String[] pp1, String[] pp2)
  4. areEquals(byte[] g1, byte[] g2)
  5. arrayCompare(byte src[], short srcOff, byte dest[], short destOff, short length)
  6. arrayCompare(byte[] a1, byte[] a2)
  7. arrayCompare(byte[] b1, byte[] b2)
  8. arrayCompare(final T[] a, final T[] b)
  9. arrayCompare(int[] arr1, int[] arr2)