Java Stream skip: How to Skip Elements in Streams
Learn how to use Java Stream skip() to drop a fixed number of elements, combine it with limit() for pagination, and understand its ordering and performance tradeoffs.

When you call skip(n) on a Java stream, the stream discards n elements and passes the remaining elements to the next operation. On an ordered stream, those are the first n elements in encounter order; on an unordered stream, which n elements are dropped is not specified. This article explains how skip() behaves, shows practical examples, and covers the ordering and performance issues that matter in real code.
What Does skip() Do in Java Streams?
The skip() method is defined on Stream<T> and on the primitive stream variants IntStream, LongStream, and DoubleStream. It returns a new stream containing the elements of the original stream after discarding n elements. If the stream has fewer than n elements, the resulting stream is empty.
skip() is a stateful intermediate operation: the implementation must keep track of elements that have been discarded before it can produce the remaining elements.
Here is the minimal syntax:
Stream<T> skipped = originalStream.skip(n);The parameter n must be non-negative. If you pass a negative value, skip() throws IllegalArgumentException because the JDK requires n >= 0. This is a common mistake when the count is computed dynamically and can become negative.
Basic Usage of skip()
The most straightforward use is to remove a fixed number of elements from the beginning of a stream. For example, suppose you have a list of integers and you want to process all elements except the first two:
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> result = numbers.stream()
.skip(2)
.collect(Collectors.toList());
// result contains [3, 4, 5]The stream starts with 1, 2, 3, 4, 5. The skip(2) operation discards the first two elements, and the remaining elements are collected into a new list.
You can also use skip() to ignore the first few lines of a file or the first few log entries. The operation works on collections, arrays, I/O-backed streams such as Files.lines(), and generated streams. What differs between sources is the cost and the ordering guarantee.
Combining skip() with limit() to Implement Pagination
A common pattern is to combine skip() and limit() to implement pagination or windowing on an ordered stream. To get a page of results from a stream, skip the first pageSize * pageNumber elements and limit the result to pageSize elements. For example, to get the third page of five elements:
int pageNumber = 2; // zero-based
int pageSize = 5;
List<String> items = getAllItems();
List<String> page = items.stream()
.skip((long) pageNumber * pageSize)
.limit(pageSize)
.collect(Collectors.toList());Semantically this works with any stream source, but for pagination to be meaningful the stream should be ordered. The source also matters for cost: a generator or I/O-backed stream must produce or read every skipped element before the requested page can be reached. A collection may be cheaper to traverse, but skip() still does not expose random access the way indexed access does.
Ordering and Statefulness: When skip() Is Not Reliable
The behavior of skip() depends on whether the stream has a defined encounter order. For streams from List, arrays, or Stream.iterate, the order is the order of the source. For streams from HashSet or Stream.generate, the order is undefined. In an unordered stream, skip(n) may discard any n elements, not necessarily the first ones in the source.
This matters when you rely on skip() to preserve a specific subset. If you create a stream from a HashSet and call skip(1), the element that is removed is not deterministic. If you need a deterministic result, ensure the stream is ordered, either by using an ordered source or by calling sorted() before skip().
Parallel streams are not a way around this. For an ordered parallel pipeline, skip(n) still means the first n elements in encounter order, but enforcing that can be expensive because the implementation must coordinate across threads. For an unordered parallel stream, the dropped elements are not specified. Use parallel streams with skip() only when you have measured a clear benefit.
Performance and Cost Considerations
skip() is not a free operation. For a generator or I/O-backed stream, the skipped elements must be produced or read before the rest can be reached. In a plain skip(n) call, that is n elements; if upstream operations are involved, the number of source elements consumed can be larger. Even for a collection, the stream pipeline does not expose indexed access, so skip() cannot generally jump straight to position n as if it were subList().
If your data is already in a List and you know the index range, subList() is often a better fit because it gives you a view of the tail without traversing the prefix. Here is a comparison for a list of a million elements:
List<String> list = new ArrayList<>(largeData);
// Builds a new list containing the tail
List<String> tail = list.stream().skip(500_000).collect(Collectors.toList());
// Gives a view of the tail backed by the original list
List<String> tailView = list.subList(500_000, list.size());The subList() version is a view backed by the original list, not an independent copy. Use it when you want to work with part of a List without a stream pipeline. If your logic includes filtering, mapping, or other stream operations before the skip, skip() is the appropriate tool because subList() cannot express those transformations.
Common Pitfalls and Alternatives to skip()
One common mistake is using skip() with a negative argument. The JDK throws an IllegalArgumentException if n < 0. Guard against negative values when the count comes from user input or a calculation.
Another pitfall is assuming that skip() can jump over elements in an unbounded generator. Stream.generate(() -> "x").skip(Long.MAX_VALUE) does not fail; it will try to discard Long.MAX_VALUE elements. With a terminal operation that reads the resulting stream, that is effectively an infinite hang; even with findFirst(), it would have to generate Long.MAX_VALUE + 1 elements before returning. There is no way to skip into the middle of an unbounded generator without a source that can jump to a position.
If you need to remove elements based on a condition rather than a fixed count, filter() is the general tool. If you specifically want to drop a prefix while a predicate is true, dropWhile() (Java 9+) is more direct. dropWhile() removes elements from the beginning as long as a predicate is true. For example:
Stream.of(1, 2, 3, 4, 5)
.dropWhile(n -> n < 3)
.forEach(System.out::println); // prints 3, 4, 5dropWhile() is a better fit when the number of elements to skip is not known in advance but depends on the element values. Use skip() only when you know the exact count.
Finally, remember that skip() is an intermediate operation, so it does nothing until a terminal operation is invoked. If you forget to call collect(), forEach(), or another terminal method, the pipeline is not executed and skip() has no effect.
Use skip() when you need to discard a fixed number of elements from a stream pipeline. For indexed collections where a view is acceptable, consider subList(); for condition-based skipping, use dropWhile().
Try matching browser tools
All toolsSmall utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Java guides
All Java guidesJava Final Keyword: Usage and Behavior
How Java's final keyword works for variables, methods, and classes, with practical examples and decision guidance for using it.
Java Final Variable: Syntax, Behavior, and Use Cases
Understand what a final variable in Java means, how initialization works, and when to use it for constants, immutability, and clearer code.
Java Duration vs Period: When to Use Each
java duration vs period: Compare Java Duration and Period to handle time-based and date-based calculations correctly. Learn syntax, conversion, and pitfalls.
Instance vs Static Variables in Java: Key Differences
Understand the difference between instance and static variables in Java, including memory, lifecycle, and when to use each.
More in Java
All Java guidesThe guides filed next to this one in Java, in library order.