takeLast()
Remove all but the last
count
elements from the streamImplementation Notes
Holds at most count
number of elements in memory before emitting them once the input stream is fully exhausted. This
Gatherer is not suitable for infinite streams. For a version that drops the last count
elements, see dropLast()
.
Signature
takeLast(int count)
count
- The positive number of elements to keep at the end of the input stream
Examples
Limit the stream to the last 3 elements
Stream
.of("A", "B", "C", "D", "E", "F", "G")
.gather(Gatherers4j.takeLast(3))
.toList();
// ["E", "F", "G"]