Java Array Equal arraysEqual(boolean[] a, boolean[] b)

Here you can find the source of arraysEqual(boolean[] a, boolean[] b)

Description

arrays Equal

License

Open Source License

Declaration

public static boolean arraysEqual(boolean[] a, boolean[] b) 

Method Source Code

//package com.java2s;
/*-//from  ww w  .j a v  a 2s . c  o  m
 * Copyright (C) 2006-2007 Erik Larsson
 * 
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static boolean arraysEqual(boolean[] a, boolean[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arraysEqual(byte[] a, byte[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arraysEqual(char[] a, char[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arraysEqual(short[] a, short[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arraysEqual(int[] a, int[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arraysEqual(long[] a, long[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arraysEqual(Object[] a, Object[] b) {
        return arrayRegionsEqual(a, 0, a.length, b, 0, b.length);
    }

    public static boolean arrayRegionsEqual(boolean[] a, int aoff, int alen, boolean[] b, int boff, int blen) {
        if (alen != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (a[aoff + i] != b[boff + i])
                    return false;
            return true;
        }
    }

    public static boolean arrayRegionsEqual(byte[] a, int aoff, int alen, byte[] b, int boff, int blen) {
        if (a.length != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (a[aoff + i] != b[boff + i])
                    return false;
            return true;
        }
    }

    public static boolean arrayRegionsEqual(char[] a, int aoff, int alen, char[] b, int boff, int blen) {
        if (alen != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (a[aoff + i] != b[boff + i])
                    return false;
            return true;
        }
    }

    public static boolean arrayRegionsEqual(short[] a, int aoff, int alen, short[] b, int boff, int blen) {
        if (alen != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (a[aoff + i] != b[boff + i])
                    return false;
            return true;
        }
    }

    public static boolean arrayRegionsEqual(int[] a, int aoff, int alen, int[] b, int boff, int blen) {
        if (alen != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (a[aoff + i] != b[boff + i])
                    return false;
            return true;
        }
    }

    public static boolean arrayRegionsEqual(long[] a, int aoff, int alen, long[] b, int boff, int blen) {
        if (alen != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (a[aoff + i] != b[boff + i])
                    return false;
            return true;
        }
    }

    public static boolean arrayRegionsEqual(Object[] a, int aoff, int alen, Object[] b, int boff, int blen) {
        if (alen != blen)
            return false;
        else {
            for (int i = 0; i < alen; ++i)
                if (!a[aoff + i].equals(b[boff + i]))
                    return false;
            return true;
        }
    }
}

Related

  1. arrayEqualsExceptNull(Object[] a1, Object[] a2)
  2. arrayEqualsSubset(final byte[] array, final int... elements)
  3. arraysAreEqual(double[] a1, double[] a2)
  4. arraysAreEqual(final byte[] array1, final byte[] array2)
  5. arraysAreEqual(Object value, Object otherValue)
  6. arraysEqual(byte array1[], byte array2[])
  7. arraysEqual(byte[] bytes, byte[] ints)
  8. arraysEqual(final Object[] a1, final Object[] a2)
  9. arraysEqual(Object[] array1, Object[] array2)