Java Array Equal arrayEquals(Object[] arr1, Object[] arr2)

Here you can find the source of arrayEquals(Object[] arr1, Object[] arr2)

Description

array Equals

License

Apache License

Declaration

public static boolean arrayEquals(Object[] arr1, Object[] arr2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static boolean arrayEquals(Object[] arr1, Object[] arr2) {
        if (arr1 == null && arr2 == null)
            return true;
        if (arr1 == null ^ arr2 == null)
            return false;
        if (!arr1.getClass().equals(arr2.getClass()))
            return false;
        if (arr1.length != arr2.length)
            return false;

        for (int i = 0; i < arr1.length; ++i) {
            Object obj1 = arr1[i];
            Object obj2 = arr2[i];
            if (obj1 == null ^ obj2 == null)
                return false;
            if (obj1 != null && !obj1.equals(obj2))
                return false;
        }/* w ww . j  a v  a2 s  .co m*/
        return true;
    }

    public static boolean arrayEquals(byte[] arr1, byte[] arr2) {
        if (arr1 == null && arr2 == null)
            return true;
        if (arr1 == null ^ arr2 == null)
            return false;
        if (!arr1.getClass().equals(arr2.getClass()))
            return false;
        if (arr1.length != arr2.length)
            return false;

        for (int i = 0; i < arr1.length; ++i) {
            byte b1 = arr1[i];
            byte b2 = arr2[i];
            if (b1 != b2)
                return false;
        }
        return true;
    }
}

Related

  1. arrayEquals(byte[] left, byte[] right)
  2. arrayEquals(int[] a1, int[] a2)
  3. arrayEquals(int[] arr1, int[] arr2)
  4. arrayEquals(Object[] a, Object[] b)
  5. arrayEquals(Object[] a, Object[] b)
  6. arrayEquals(Object[] array1, Object[] array2)
  7. arrayEquals(Object[] source, Object target)
  8. arrayEquals(Object[] source, Object target)
  9. arrayEquals(String[] array1, String[] array2)