private static boolean compareArrays(Object array1, Object array2, Deque stack, Set visited)
    {
        // Same instance check already performed...

        int len = Array.getLength(array1);
        if (len != Array.getLength(array2))
        {
            return false;
        }

        for (int i = 0; i < len; i++)
        {
            DualKey dk = new DualKey(Array.get(array1, i), Array.get(array2, i));
            if (!visited.contains(dk))
            {   // push contents for further comparison
                stack.addFirst(dk);
            }
        }
        return true;
    }
private static boolean compareArrays ( Object array1 , Object array2 , Deque stack , Set visited ) { int len = Array . getLength ( array1 ) ; if ( len != Array . getLength ( array2 ) ) { return false ; } for ( int i = 0 ; i < len ; i ++ ) { DualKey dk = new DualKey ( Array . get ( array1 , i ) , Array . get ( array2 , i ) ) ; if ( ! visited . contains ( dk ) ) { stack . addFirst ( dk ) ; } } return true ; }
Deeply compare to Arrays []. Both arrays must be of the same type, same length, and all
elements within the arrays must be deeply equal in order to return true.
@param array1 [] type (Object[], String[], etc.)
@param array2 [] type (Object[], String[], etc.)
@param stack add items to compare to the Stack (Stack versus recursion)
@param visited Set of objects already compared (prevents cycles)
@return true if the two arrays are the same length and contain deeply equivalent items.