Java Iterable sequenceEqual(Iterable one, Iterable two)

Here you can find the source of sequenceEqual(Iterable one, Iterable two)

Description

Compares two sequences of values and returns true if sequence members are equal and in the same order

License

Open Source License

Declaration

public static <T> boolean sequenceEqual(Iterable<T> one, Iterable<T> two) 

Method Source Code


//package com.java2s;
/*//from w w  w .j a v a 2s.com
 * IRIS -- Intelligent Roadway Information System
 * Copyright (C) 2015 California Department of Transportation
 *
 * 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 2 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.
 */

import java.util.Iterator;

public class Main {
    /** Compares two sequences of values and returns true if sequence members are equal and in the same order */
    public static <T> boolean sequenceEqual(Iterable<T> one, Iterable<T> two) {
        Iterator<T> iter1 = one.iterator();
        Iterator<T> iter2 = two.iterator();

        while (iter1.hasNext() && iter2.hasNext()) {
            if (iter1.next() != iter2.next()) {
                return false;
            }
        }
        return (!iter1.hasNext() && !iter2.hasNext());
    }
}

Related

  1. mergeConsecutiveTokens(Iterable tokens)
  2. prettyPrintComma(Iterable a)
  3. removeElement(final Iterable iterable, int index)
  4. removeIgnoreCase(Iterable haystack, String needle)
  5. secondOf(final Iterable iterable)
  6. shallowCopy(Iterable ori)
  7. toFriendlyString(Iterable iterable, String seperator)
  8. unique(Iterable source, T defaultElement)
  9. valueOfMultiple(Iterable... iterables)