Here you can find the source of startsWith(Stream
assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3)));
Parameter | Description |
---|---|
iterable | a parameter |
public final static <T> boolean startsWith(Stream<T> stream, Iterable<T> iterable)
//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; } }