Here you can find the source of equals(Collection> collection1, Collection> collection2)
public static boolean equals(Collection<?> collection1, Collection<?> collection2)
//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()); } }