You are adding them as Integers and java has limit for Integer value 2147483647. If you pass this max value you will start to count from minimum value Integer.MAX_VALUE + 1 = -2147483648.

Answer from Maciej Niedźwiedź on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java streams › java stream skip() vs limit()
Java Stream skip() vs limit() | Baeldung
January 8, 2024 - In this short article, we’ll talk about the skip() and limit() methods of the Java Stream API and highlight their similarities and differences. Even though these two operations may look quite similar at first, they actually behave very differently and are not interchangeable. Actually, they’re complementary and can be handy when used together. Keep reading to learn more about them. The skip(n) method is an intermediate operation that discards the first n elements of a stream. The n parameter can’t be negative, and if it’s higher than the size of the stream, skip() returns an empty stream.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › stream › Stream.html
Stream (Java Platform SE 8 )
3 weeks ago - maxSize - the number of elements the stream should be limited to · Returns: the new stream · Throws: IllegalArgumentException - if maxSize is negative · Stream<T> skip(long n) Returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream.
🌐
Baeldung
baeldung.com › home › lesson 4: limit(), skip()
Lesson 4: limit(), skip() - Baeldung Membership
October 14, 2025 - If the limit() operation receives a value greater than or equal to the number of elements in the source, it has no effect, and all elements are returned. If limit(0) is used, it returns an empty stream, effectively discarding all the elements. However, if limit() is given a negative value, it’ll throw an IllegalArgumentException.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Java 8 Stream API - limit() & skip() - Examples Java Code Geeks - 2026
December 17, 2021 - 'n' cannot be a negative number and if it is higher // than the size of stream, the skip() method will return an empty stream // syntax - Stream<T> skip(long n); private static void method1() { // creating a numbers list List<Integer> numbers ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › stream-limit-method-in-java
stream.limit() method in Java - GeeksforGeeks
August 27, 2024 - ... If the value of N is negative, then IllegalArgumentException is thrown by the function. Below are some examples to understand the implementation of the function in a better way.
🌐
Netjstech
netjstech.com › 2021 › 09 › java-stream-limit-with-examples.html
Java Stream - limit() With Examples | Tech Tutorials
March 5, 2024 - Java Stream API limit(long maxSize) ... the stream should be limited to. If maxSize is negative then IllegalArgumentException is thrown otherwise a new Stream is returned which is no longer than maxSize in length....
🌐
Medium
medium.com › geekculture › java-streams-limit-and-skip-24c9732c60a
Java Streams: Limit and Skip | Geek Culture
May 18, 2022 - The limit(n) intermediate operation will truncate the stream to the size of just n elements. n should be a non-negative long number, since negative ones will make it throw an IllegalArgumentException .
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java stream limit()
Java Stream limit() with Example - HowToDoInJava
March 30, 2022 - We can use Stream.limit(long) to retrieve elements while they must not be greater than a certain maximum count. Java 8 Stream limit() example
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › javas-stream-limit-method-explained-b1f872252828
Java’s Stream.limit() Method Explained | Medium
January 14, 2025 - Streams, by their nature, are lazy and do not load all elements into memory at once. However, the limit() method takes this efficiency further by restricting the number of elements processed, thereby reducing the overall memory footprint. For example, when reading large files, you may want to process only the first few lines to avoid loading the entire file into memory: import java.nio.file.Files; import java.nio.file.Paths; import java.util.stream.Stream; public class FileReadExample { public static void main(String[] args) { try (Stream<String> lines = Files.lines(Paths.get("largefile.txt"))) { lines.limit(10).forEach(System.out::println); } catch (Exception e) { e.printStackTrace(); } } }
🌐
Javaprogramto
javaprogramto.com › 2020 › 08 › java-8-stream-limit-method-example.html
Java 8 Stream limit() Method Example JavaProgramTo.com
August 17, 2020 - If negative then it will throw IllegalArgumentException. 3.9 Retured stream picks the elemtns from the previous intermediate operation such as map() or filter() methods output as how they appear in the sequential order.
🌐
Stack Overflow
stackoverflow.com › questions › 55328146 › java-stream-parameter-limit-with-no-limit-mongodb-inconsistency
Java stream parameter limit with no limit (MongoDB inconsistency) - Stack Overflow
Java streams in memory can be very long or even infinity (for example IntStream.iterate(0, i -> i + 1)) and there is may be a case where Long.MAX_VALUE is too small. ... Use the last version. When you don’t want a limit, don’t call limit, but avoid code duplication.
🌐
ConcretePage
concretepage.com › java › java-8 › java-stream-limit
Java Stream limit()
May 8, 2024 - The limit method of Stream returns a new stream consisting the elements of this stream truncated to given max size in length. The limit method consists the first n elements where n is less or equal to given max size.
🌐
Java Guides
javaguides.net › 2024 › 07 › java-stream-limit-method.html
Java Stream limit() Method
July 3, 2024 - IllegalArgumentException: If maxSize is negative. The limit() method allows you to limit the number of elements in a stream to a specified maximum size. This is particularly useful when you only need to process a subset of the elements in a stream.
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-limit-java
IntStream limit() in Java - GeeksforGeeks
July 11, 2025 - Return Value : The function returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length. Exception : The function throws IllegalArgumentException if maxSize is negative.
🌐
Boraji
boraji.com › java-8-stream-limit-and-skip-methods-example
https://boraji.com/java-8-stream-limit-and-skip-me...
April 3, 2017 - A blog for learner and developer to learn Java SE, Java EE, Spring Core, Spring MVC, Spring Boot, Hibernate ORM, Maven build tool, Eclipse IDE, Lambda Expression, IO Stream ,JFreeChart Library and more tutorials with easy and simple examples.
🌐
YouTube
youtube.com › java techie
Java 8 Stream | Skip() and Limit() Methods With Realtime Example | JavaTechie - YouTube
This tutorial will helps you to understand real usecase of skip(n) and limit(n) method in java 8 stream API with detailed explanationSpring boot microservice...
Published   September 27, 2022
Views   17K
🌐
Educative
educative.io › answers › what-is-the-limit-method-of-stream-interface
What is the limit() method of Stream Interface?
This performance issue can be avoided ... a sequential stream instead of a parallel stream. IllegalArgumentException is thrown if we pass negative numbers as the value for N....