Here you can find the source of isEqual(Collection
Parameter | Description |
---|---|
a | The first collection to compare |
b | The second collection to compare |
T | The generic type of the collections to compare |
public static <T> boolean isEqual(Collection<T> a, Collection<T> b)
//package com.java2s; /**/*from ww w. j av a2 s.c om*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ import java.util.Collection; import java.util.Iterator; public class Main { /** * @param a The first value to compare * @param b The second value to compare * @param <T> The type of the values * @return true if a == b or a equals b */ public static <T> boolean isEqual(T a, T b) { return a == b || (a != null) && a.equals(b); } /** * @param a The first collection to compare * @param b The second collection to compare * @param <T> The generic type of the collections to compare * @return true if a == b or a and b contain equal elements in the same order */ public static <T> boolean isEqual(Collection<T> a, Collection<T> b) { if (a == null) { return b == null; } if (b == null) { return false; } if (a.size() != b.size()) { return false; } for (Iterator<T> itA = a.iterator(), itB = b.iterator(); itA.hasNext();) { if (!isEqual(itA.next(), itB.next())) { return false; } } return true; } }