public Stream < T > take ( final int count ) { return new Stream < T > ( ) { @ Override public Iterator < T > iterator ( ) { return new ReadOnlyIterator < T > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; int left = count ; @ Override public boolean hasNext ( ) { return left > 0 && iterator . hasNext ( ) ; } @ Override public T next ( ) { left -- ; return iterator . next ( ) ; } } ; } } ; }
Creates a new stream that contains only the first given amount of items of the current stream .