# Interface CloseableIterator<T>

All Superinterfaces:
  `AutoCloseable, Closeable, Iterator<T>`

All Known Subinterfaces:
  `CloseableTribbleIterator<T>, SAMRecordIterator, VCFIterator`

All Known Implementing Classes:
  `AbstractLocusIterator, AsyncBufferedIterator, BAMFileReader.BAMQueryFilteringIterator, CRAMIterator, DelegatingIterator, DownsamplingIterator, DuplicateSetIterator, EdgeReadIterator, FilteringIterator, FilteringIterator, FilteringSamIterator, FilteringVariantContextIterator, MergingIterator, MergingSamRecordIterator, PeekableIterator, SamLocusIterator, SamPairUtil.SetMateInfoIterator, SamReader.AssertingIterator, SAMRecordPrefetchingIterator`

public interface CloseableIterator<T> extends Iterator<T>, Closeable
This interface is used by iterators that use releasable resources during iteration. The consumer of a CloseableIterator should ensure that the close() method is always called, for example by putting such a call in a finally block. Two conventions should be followed by all implementors of CloseableIterator: 1) The close() method should be idempotent: calling close() twice should have no effect. 2) When hasNext() returns false, the iterator implementation should automatically close itself. The latter makes it somewhat safer for consumers to use the for loop syntax for iteration: for (Type obj : getCloseableIterator()) { ... }

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Should be implemented to close/release any underlying resources.
`default Stream<T>`
`stream()`
Returns a Stream that will consume from the underlying iterator.
`default List<T>`
`toList()`
Consumes the contents of the iterator and returns it as a List.

### Methods inherited from interface Iterator

`forEachRemaining, hasNext, next, remove`

## Method Details

### close

void close()
Should be implemented to close/release any underlying resources.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`

### toList

default List<T> toList()
Consumes the contents of the iterator and returns it as a List.

### stream

default Stream<T> stream()
Returns a Stream that will consume from the underlying iterator.