Iterable equal - Java Collection Framework

Java examples for Collection Framework:Iterable

Description

Iterable equal

Demo Code


//package com.java2s;
import java.util.Iterator;

public class Main {

    public static <T> boolean equal(Iterable<T> first, Iterable<T> second) {
        return equal(first.iterator(), second.iterator());
    }/*  w  w  w.j av  a2  s. c  o m*/

    public static <T> boolean equal(Iterator<T> first, Iterator<T> second) {
        while (first.hasNext() && second.hasNext()) {
            T message = first.next();
            T otherMessage = second.next();
            /* Element? ??? ? */
            if (!(message == null ? otherMessage == null : message
                    .equals(otherMessage))) {
                return false;
            }
        }
        /* ????? ??? ? */
        return !(first.hasNext() || second.hasNext());
    }
}

Related Tutorials