Java SE API

Stream.dropWhile()

For ordered streams, discards the matching prefix. Since Java 9; unordered semantics differ. Java SE API; example uses Java 21-compatible syntax.

Formal Syntax & Structure

java syntaxjava
default Stream<T> dropWhile(Predicate<? super T> predicate)

Parameters & Attributes

NameTypeDescription
predicatePredicate<? super T>Prefix test

Return Value

Stream<T>

For ordered streams, discards the matching prefix. Since Java 9; unordered semantics differ.

Working Example

Example Snippetjava
import java.util.*;import java.util.stream.*;public class Main {    public static void main(String[] args) {        var values = List.of(2, 4, 7, 6);        System.out.println(values.stream().takeWhile(n -> n % 2 == 0).toList());        System.out.println(values.stream().dropWhile(n -> n % 2 == 0).toList());        System.out.println(values.stream().filter(n -> n % 2 == 0).toList());    }}
Java Reference