@NotNull
    public Stream<T> limit(final long maxSize) {
        if (maxSize < 0) {
            throw new IllegalArgumentException("maxSize cannot be negative");
        }
        if (maxSize == 0) {
            return Stream.empty();
        }
        return new Stream<T>(params, new ObjLimit<T>(iterator, maxSize));
    }
@ NotNull public Stream < T > limit ( final long maxSize ) { if ( maxSize < 0 ) { throw new IllegalArgumentException ( "maxSize cannot be negative" ) ; } if ( maxSize == 0 ) { return Stream . empty ( ) ; } return new Stream < T > ( params , new ObjLimit < T > ( iterator , maxSize ) ) ; }
Returns {@code Stream} with first {@code maxSize} elements.

<p>This is a short-circuiting stateful intermediate operation.

<p>Example:
<pre>
maxSize: 3
stream: [1, 2, 3, 4, 5]
result: [1, 2, 3]

maxSize: 10
stream: [1, 2]
result: [1, 2]
</pre>

@param maxSize  the number of elements to limit
@return the new stream
@throws IllegalArgumentException if {@code maxSize} is negative