Java Stream Operation startsWith(Stream stream, Iterable iterable)

Here you can find the source of startsWith(Stream stream, Iterable iterable)

Description

   assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3))); 

License

Open Source License

Parameter

Parameter Description
iterable a parameter

Return

True if Monad starts with Iterable sequence of data

Declaration

public final static <T> boolean startsWith(Stream<T> stream, Iterable<T> iterable) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;

import java.util.Objects;

import java.util.stream.Stream;

public class Main {
    /**//from   w w  w. j a  v a  2s . c o  m
     * 
     * <pre>{@code 
     * assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3)));
     * }</pre>
     * 
     * @param iterable
     * @return True if Monad starts with Iterable sequence of data
     */
    public final static <T> boolean startsWith(Stream<T> stream, Iterable<T> iterable) {
        return startsWith(stream, iterable.iterator());

    }

    /**
     *    <pre>
     * {@code
     *        assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3).iterator())) 
     * }</pre>
        
     * @param iterator
     * @return True if Monad starts with Iterators sequence of data
     */
    public final static <T> boolean startsWith(Stream<T> stream, Iterator<T> iterator) {
        Iterator<T> it = stream.iterator();
        while (iterator.hasNext()) {
            if (!it.hasNext())
                return false;
            if (!Objects.equals(it.next(), iterator.next()))
                return false;
        }
        return true;

    }
}

Related

  1. rebuildParallel(Stream stream)
  2. replacePos(StringBuilder original, char replacementChar, Stream positionsToReplace)
  3. replaceStr(StringBuilder original, char replacementChar, Stream stringsToReplace)
  4. reverse(Stream stream)
  5. reverse(Stream input)
  6. startsWith(Stream stream, Stream stream2)
  7. stringPositions(StringBuilder toTest, Stream strings)
  8. toList(final Stream stream)
  9. toParameter(Stream input, Class exp)