Package htsjdk.samtools.util

# Class PeekableIterator<Object>

java.lang.Object
htsjdk.samtools.util.PeekableIterator<Object>

All Implemented Interfaces:
  `CloseableIterator<Object>`, `Closeable`, `AutoCloseable`, `Iterator<Object>`

Direct Known Subclasses:
  `SamPairUtil.SetMateInfoIterator`

public class PeekableIterator<Object> extends Object implements CloseableIterator<Object>
Generic Closable Iterator that allows you to peek at the next value before calling next

## Constructor Summary

Constructors
Constructor
Description
`PeekableIterator(Iterator<Object> iterator)`
Constructs a new iterator that wraps the supplied iterator.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Closes the underlying iterator.
`boolean`
`hasNext()`
True if there are more items, in which case both next() and peek() will return a value.
`Object`
`next()`
Returns the next object and advances the iterator.
`Object`
`peek()`
Returns the next object but does not advance the iterator.
`void`
`remove()`
Unsupported Operation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface htsjdk.samtools.util.CloseableIterator

`stream, toList`

### Methods inherited from interface java.util.Iterator

`forEachRemaining`

## Constructor Details

### PeekableIterator

public PeekableIterator(Iterator<Object> iterator)
Constructs a new iterator that wraps the supplied iterator.

## Method Details

### close

public void close()
Closes the underlying iterator.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `CloseableIterator<Object>`

### hasNext

public boolean hasNext()
True if there are more items, in which case both next() and peek() will return a value.

Specified by:
  `hasNext` in interface `Iterator<Object>`

### next

public Object next()
Returns the next object and advances the iterator.

Specified by:
  `next` in interface `Iterator<Object>`

### peek

public Object peek()
Returns the next object but does not advance the iterator. Subsequent calls to peek() and next() will return the same object.

### remove

public void remove()
Unsupported Operation.

Specified by:
  `remove` in interface `Iterator<Object>`