Java Iterator areEqual(final Iterator ittyA, final Iterator ittyB)

Here you can find the source of areEqual(final Iterator ittyA, final Iterator ittyB)

Description

Checks if the contents of the two iterators are equal and of the same length.

License

Apache License

Parameter

Parameter Description
ittyA An iterator
ittyB An iterator

Return

Returns true if the two iterators contain the same objects and are of the same length

Declaration

public static boolean areEqual(final Iterator ittyA,
        final Iterator ittyB) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;

public class Main {
    /**//  w  ww  .  java  2s .  co m
     * Checks if the contents of the two iterators are equal and of the same length.
     * Equality is determined using == operator on the internal objects.
     *
     * @param ittyA An iterator
     * @param ittyB An iterator
     * @return Returns true if the two iterators contain the same objects and are of the same length
     */
    public static boolean areEqual(final Iterator ittyA,
            final Iterator ittyB) {
        if (ittyA.hasNext() != ittyB.hasNext())
            return false;

        while (ittyA.hasNext()) {
            if (!ittyB.hasNext())
                return false;
            if (ittyA.next() != ittyB.next())
                return false;
        }
        return true;
    }
}

Related

  1. addAllToList(Iterator i)
  2. addAllToSet(Set set, Iterator it)
  3. addTo(final Iterator iter, final C c)
  4. appendTo(final Iterator iter, final List list)
  5. areEqual(final Iterator a, final Iterator b)
  6. asArray(T[] arr, Iterator itr)
  7. asList(final Iterator iterator)
  8. asList(Iterator it)
  9. asStringOn(StringBuffer sb, Iterator iter, String separator)