Here you can find the source of isEqual(Collection one, Collection two)
Parameter | Description |
---|---|
one | a Collection |
two | a Collection |
public static boolean isEqual(Collection one, Collection two)
//package com.java2s; /*/*from www .j av a 2 s . c o m*/ * Copyright 2014 Johns Hopkins University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; public class Main { /** * Calculates the equality of two collections disregarding the underlying implementation. Specifically this allows * (for example) a {@code Collection} implemented using an {@code ArrayList} and a {@code Collection} implemented * using a {@code HashSet} to be compared for equality. * <p> * This method uses {@link Collection#containsAll(java.util.Collection)} to determine equality of the supplied * collections. * * @param one a Collection * @param two a Collection * @return true if the collections are equal */ public static boolean isEqual(Collection one, Collection two) { if (one == null && two != null) { return false; } if (one != null && two == null) { return false; } if (one == two) { return true; } return one.containsAll(two) && two.containsAll(one); } }