Here you can find the source of equals(Iterable> collection1, Iterable> collection2)
Parameter | Description |
---|---|
collection1 | a parameter |
collection2 | a parameter |
public static boolean equals(Iterable<?> collection1, Iterable<?> collection2)
//package com.java2s; /******************************************************************************* * Copyright 2011 Danny Kunz//from www .j a v a 2 s . c o m * * 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.Iterator; public class Main { /** * Returns true if the elements of the two given {@link Collection}s are equal and have the same order * * @param collection1 * @param collection2 * @return */ public static boolean equals(Iterable<?> collection1, Iterable<?> collection2) { // boolean retval = false; // if (collection1 != null && collection2 != null) { // Iterator<?> iteratorOther = collection2.iterator(); Iterator<?> iteratorThis = collection1.iterator(); // retval = true; // while (iteratorOther.hasNext() && iteratorThis.hasNext()) { // Object elementOther = iteratorOther.next(); Object elementThis = iteratorThis.next(); // retval &= elementThis == elementOther || (elementThis != null && elementThis.equals(elementOther)); // if (!retval) { break; } } // retval &= !iteratorOther.hasNext() && !iteratorThis.hasNext(); } // return retval; } }