takeEveryNth()
Take every
n
th element of the stream.Implementation Notes
This is syntactic sugar on top of filterIndexed()
. For a version
of this gatherer that drops every nth element instead of taking them, see the dropEveryNth()
Gatherer.
Signature
takeEveryNth(int count)
count
- The periodic number of the elements to drop, must be at least 2
Examples
Take every 3rd element
Stream
.of("A", "B", "C", "D", "E", "F", "G")
.gather(Gatherers4j.takeEveryNth(3))
.toList();
// ["A", "D", "G"]