Java Array Equal equalsIgnoreSequence(Object[] array1, Object[] array2)

Here you can find the source of equalsIgnoreSequence(Object[] array1, Object[] array2)

Description

equals Ignore Sequence

License

Apache License

Declaration

public static boolean equalsIgnoreSequence(Object[] array1, Object[] array2) 

Method Source Code

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

import java.util.Arrays;

import java.util.List;

public class Main {

    public static boolean equalsIgnoreSequence(Object[] array1, Object[] array2) {
        if ((array1 == null) && (array2 == null)) {
            return true;
        } else if ((array1 == null) || (array2 == null)) {
            return false;
        }/*from  www. jav  a 2 s.  c  o m*/
        if (array1.length != array2.length) {
            return false;
        }
        List<Object> list = Arrays.asList(array2);
        for (int i = 0; i < array1.length; i++) {
            Object o1 = array1[i];
            if (!list.contains(o1)) {
                return false;
            }
        }
        return true;
    }

    public static boolean contains(Object[] array, Object obj) {
        return -1 < indexOf(array, obj);
    }

    public static boolean contains(char[] array, char ch) {
        return -1 < indexOf(array, ch);
    }

    public static int indexOf(Object[] array, Object obj) {
        if (array != null) {
            for (int i = 0; i < array.length; ++i) {
                Object o = array[i];
                if (o != null) {
                    if (o.equals(obj)) {
                        return i;
                    }
                } else if (obj == null) {
                    return i;

                }
            }
        }
        return -1;
    }

    public static int indexOf(char[] array, char ch) {
        if (array != null) {
            for (int i = 0; i < array.length; ++i) {
                char c = array[i];
                if (ch == c) {
                    return i;
                }
            }
        }
        return -1;
    }
}

Related

  1. equals(String[] fullSet, String[] subSet)
  2. equals(T[] array1, T[] array2)
  3. equals3(double[][][] arr1, double[][][] arr2)
  4. equalsAny(T element, T[] array)
  5. equalsIgnoreSequence(final T[] array1, final T[] array2)
  6. equalsToElement(final Object[] arr, final Object obj)
  7. equalStringArrays(String[] expected, String[] actual)
  8. findMinimaGreaterOrEqual(final int[] min, final int elt)
  9. getClosestIndexEqualToOrLargerThanGivenCoordinate(double[] coordinates, double coordinate)