Java Stream Operation equals(Stream first, Stream second)

Here you can find the source of equals(Stream first, Stream second)

Description

equals

License

Open Source License

Declaration

public static boolean equals(Stream<?> first, Stream<?> second) 

Method Source Code

//package com.java2s;
/*//  ww  w.  j  a va2s  .c om
 * Copyright (C) 2018 Scientific Analysis Instruments Limited <contact@saiman.co.uk>
 *          ______         ___      ___________
 *       ,'========\     ,'===\    /========== \
 *      /== \___/== \  ,'==.== \   \__/== \___\/
 *     /==_/____\__\/,'==__|== |     /==  /
 *     \========`. ,'========= |    /==  /
 *   ___`-___)== ,'== \____|== |   /==  /
 *  /== \__.-==,'==  ,'    |== '__/==  /_
 *  \======== /==  ,'      |== ========= \
 *   \_____\.-\__\/        \__\\________\/
 *
 * This file is part of uk.co.saiman.collections.
 *
 * uk.co.saiman.collections 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 3 of the License, or
 * (at your option) any later version.
 *
 * uk.co.saiman.collections 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Iterator;

import java.util.Objects;

import java.util.stream.Stream;

public class Main {
    public static boolean equals(Stream<?> first, Stream<?> second) {
        Iterator<?> firstIterator = first.iterator();
        Iterator<?> secondIterator = second.iterator();

        while (firstIterator.hasNext() && secondIterator.hasNext()) {
            if (!Objects.equals(firstIterator.next(), secondIterator.next())) {
                return false;
            }
        }

        return !firstIterator.hasNext() && !secondIterator.hasNext();
    }
}

Related

  1. concat(Stream... streams)
  2. containsOnly(Stream stream, long size)
  3. createStream(final Iterator iterator)
  4. endsWith(Stream stream, Iterable iterable)
  5. enumerationAsStream(Enumeration e)
  6. factorStream(long number)
  7. filterInstances(Stream stream, Class clazz)
  8. filterType(Stream stream, Class type)
  9. findLast(Stream s)