Here you can find the source of equalsIterablesInOrder(Iterable> i1, Iterable> i2)
public static boolean equalsIterablesInOrder(Iterable<?> i1, Iterable<?> i2)
//package com.java2s; /******************************************************************************* * The MIT License (MIT)//from w ww . jav a 2s . c om * * Copyright (c) 2016 Dalibor Drgo? <emptychannelmc@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ import java.util.Collection; import java.util.Iterator; public class Main { /** * Check if values in iterables are identical and in identical order * If both are instanceof Collection, this method check sizes first * Calls only once Itarable#iterator() for both iterables */ public static boolean equalsIterablesInOrder(Iterable<?> i1, Iterable<?> i2) { if (i1 == i2) { return true; } if (i1 == null) { if (i2 == null) { return true; } return false; } else if (i2 == null) { return false; } if (i1 instanceof Collection && i2 instanceof Collection) { if (((Collection<?>) i1).size() != ((Collection<?>) i2).size()) { return false; } } Iterator<?> it1 = i1.iterator(); Iterator<?> it2 = i2.iterator(); while (it1.hasNext()) { if (!it2.hasNext()) { return false; } Object c1 = it1.next(); Object c2 = it2.next(); if ((c1 == null) ? c2 != null : !c1.equals(c2)) { return false; } } return !it2.hasNext(); } public static boolean equals(Object[] one, Object[] two, int size) { if (one == two) { return true; } while (size-- != 0) { Object on = one[size]; Object tw = two[size]; if ((on == null) ? tw != null : !on.equals(tw)) { return false; } } return true; } public static boolean equals(Object[] one, int off1, Object[] two, int off2, int size) { if (one == two && off1 == off2) { return true; } size += off1; for (; off1 < size; off1++, off2++) { Object on = one[off1]; Object tw = two[off2]; if ((on == null) ? tw != null : !on.equals(tw)) { return false; } } return true; } }