skip(n) — discards exactly n elements. dropWhile(predicate) — discards elements while a condition is true. Think of skip() as fast-forwarding exactly 5 minutes, while dropWhile() as fast-forwarding until you reach a scene you want to watch.
skip():
1List<Integer> result = List.of(1,2,3,4,5).stream()2 .skip(2)3 .toList();4// [3, 4, 5]
dropWhile():
1List<Integer> result = List.of(1,2,3,4,5).stream()2 .dropWhile(x -> x < 3)3 .toList();4// [3, 4, 5]
Key difference:
1// Real-world: skip to page 3 (skip 20 items)2list.stream().skip(20).limit(10).collect(toList());34// Real-world: drop entries before a cutoff5logEntries.stream()6 .sorted(Comparator.comparing(LogEntry::getTimestamp))7 .dropWhile(e -> e.getTimestamp().isBefore(cutoff))8 .collect(toList());