Here you can find the source of compareCollections(Collection value1, Collection value2)
Parameter | Description |
---|---|
value1 | first value or null |
value2 | second value or null |
public static boolean compareCollections(Collection value1, Collection value2)
//package com.java2s; /**/* w w w.j a va 2 s . c o m*/ * Copyright (C) 2010 Orbeon, Inc. * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU Lesser General Public License as published by the Free Software Foundation; either version * 2.1 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * The full text of the license is available at http://www.gnu.org/copyleft/lesser.html */ import java.util.*; public class Main { /** * Compare two collections, handling null values as well. * * @param value1 first value or null * @param value2 second value or null * @return whether the values are identical or both null */ public static boolean compareCollections(Collection value1, Collection value2) { // Add quick check on size, which AbstractList e.g. doesn't do return (value1 == null && value2 == null) || (value1 != null && value2 != null && value1.size() == value2.size() && value1 .equals(value2)); } }