Java Array Equal arrayEqualsExceptNull(Object[] a1, Object[] a2)

Here you can find the source of arrayEqualsExceptNull(Object[] a1, Object[] a2)

Description

array Equals Except Null

License

Open Source License

Declaration

public static boolean arrayEqualsExceptNull(Object[] a1, Object[] a2) 

Method Source Code

//package com.java2s;
/*/*from w  w w .ja v a2s .c  om*/
 * Copyright (C) Jakub Neubauer, 2007
 *
 * This file is part of TaskBlocks
 *
 * TaskBlocks 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.
 *
 * TaskBlocks 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 arrayEqualsExceptNull(Object[] a1, Object[] a2) {
        if ((a1 == null) && (a2 == null)) {
            return true;
        }
        if (a1 == null && a2 != null && a2.length == 0) {
            return true;
        }
        if (a2 == null && a1 != null && a1.length == 0) {
            return true;
        }
        if (((a1 == null) && (a2 != null)) || ((a2 == null) && (a1 != null))) {
            return false;
        }
        if (a1.length != a2.length) {
            return false;
        }
        for (int i = 0; i < a1.length; i++) {
            if ((a1[i] == null) && (a2[i] == null)) {
                continue;
            }
            if ((a1 != null) && a1[i].equals(a2[i])) {
                continue;
            }
            return false;
        }
        return true;
    }
}

Related

  1. arrayEquals(Object[] array1, Object[] array2)
  2. arrayEquals(Object[] source, Object target)
  3. arrayEquals(Object[] source, Object target)
  4. arrayEquals(String[] array1, String[] array2)
  5. arrayEquals(String[] targetMethodParamTypes, String[] paramTypes)
  6. arrayEqualsSubset(final byte[] array, final int... elements)
  7. arraysAreEqual(double[] a1, double[] a2)
  8. arraysAreEqual(final byte[] array1, final byte[] array2)
  9. arraysAreEqual(Object value, Object otherValue)