Here you can find the source of equal(List coll, List otherColl)
@SuppressWarnings("unchecked") public static boolean equal(List coll, List otherColl)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2012//from w ww. j av a 2 s . c o m * Software Technology Group, Dresden University of Technology * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026 * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Software Technology Group - TU Dresden, Germany; * DevBoost GmbH - Berlin, Germany * - initial API and implementation ******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { @SuppressWarnings("unchecked") public static boolean equal(List coll, List otherColl) { // trivial checks if (coll == null && otherColl == null) return true; // size checks if (coll == null && otherColl != null && otherColl.size() < 1) return true; if (coll != null && coll.size() < 1 && otherColl == null) return true; // trivial null check if (coll != null && coll.size() > 0 && otherColl == null) return false; if (coll == null && otherColl != null && otherColl.size() > 0) return false; // both empty if (coll.size() == 0 && otherColl.size() == 0) return true; List list = new ArrayList<Object>(); list.addAll(coll); List otherList = new ArrayList<Object>(); otherList.addAll(otherColl); if (list == null || list.size() < 1) return false; if (otherList != null) { boolean contains; boolean equal = true; Object obj; for (Object newObj : list) { contains = false; obj = null; for (Object oldObj : otherList) { if (newObj.equals(oldObj)) { contains = true; obj = oldObj; break; } } equal = equal && contains; if (!equal) break; otherList.remove(obj); } for (Object oldObj : otherList) { if (!equal) break; contains = false; obj = null; for (Object newObj : list) { if (oldObj.equals(newObj)) { contains = true; break; } } equal = equal && contains; } if (equal) return true; } return false; } }