Java Collection Equal equals(Collection collection1, Collection collection2)

Here you can find the source of equals(Collection collection1, Collection collection2)

Description

equals

License

Open Source License

Declaration

public static boolean equals(Collection<?> collection1, Collection<?> collection2) 

Method Source Code


//package com.java2s;
/*//from   ww  w.j a v a  2  s  .  c  om
 * @(#)CollectionUtility.java
 *
 * Copyright 2003 by EkoLiving Pty Ltd.  All Rights Reserved.
 *
 * This software is the proprietary information of EkoLiving Pty Ltd.
 * Use is subject to license terms.
 */

import java.util.*;

public class Main {
    /**
     * Compares two Iterators for equality.
     *
     * @return true if Iterator elements are equal
     */

    public static boolean equals(Iterator<?> iterator1, Iterator<?> iterator2) {

        HashSet<Object> hashSet1 = new HashSet<Object>();
        HashSet<Object> hashSet2 = new HashSet<Object>();

        while (iterator1.hasNext())
            hashSet1.add(iterator1.next());
        while (iterator2.hasNext())
            hashSet2.add(iterator2.next());

        return (hashSet1.equals(hashSet2));
    }

    public static boolean equals(Collection<?> collection1, Collection<?> collection2) {
        return (collection1.containsAll(collection2) && collection2.size() == collection1.size());
    }
}

Related

  1. equalCollection(Collection c1, Collection c2)
  2. equalContent(Collection col1, Collection col2)
  3. equalContent(final Collection a, final Collection b)
  4. equals(Collection c1, Collection c2)
  5. equals(Collection collection1, Collection collection2)
  6. equals(Collection a, Collection b, boolean ordered)
  7. equals(final Collection c1, final Collection c2)
  8. equals(Iterable collection1, Iterable collection2)
  9. equalsAny(Object object, Collection objects)

    HOME | Copyright © www.java2s.com 2016