org.apache.commons.collections4.iterators

## Class PermutationIterator<E>

- java.lang.Object
- - org.apache.commons.collections4.iterators.PermutationIterator<E>

- Type Parameters:
    `E` - the type of the objects being permuted
  All Implemented Interfaces:
    Iterator<List<E>>

      public class PermutationIterator<E>
      extends Object
      implements Iterator<List<E>>

  This iterator creates permutations of an input collection, using the Steinhaus-Johnson-Trotter algorithm (also called plain changes).

  The iterator will return exactly n! permutations of the input collection. The `remove()` operation is not supported, and will throw an `UnsupportedOperationException`.

  NOTE: in case an empty collection is provided, the iterator will return exactly one empty list as result, as 0! = 1.

  Since:
    4.0
  Version:
    $Id: PermutationIterator.java 1533984 2013-10-20 21:12:51Z tn $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PermutationIterator(Collection<? extends E> coll)` Standard constructor for this class.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `hasNext()` Indicates if there are more permutation available.
    `List<E>` | `next()` Returns the next permutation of the input collection.
    `void` | `remove()`

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

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

- - ### Constructor Detail

    - #### PermutationIterator

          public PermutationIterator(Collection<? extends E> coll)

      Standard constructor for this class.
      Parameters:
        `coll` - the collection to generate permutations for
      Throws:
        `NullPointerException` - if coll is null

  - ### Method Detail

    - #### hasNext

          public boolean hasNext()

      Indicates if there are more permutation available.
      Specified by:
        `hasNext` in interface `Iterator<List<E>>`
      Returns:
        true if there are more permutations, otherwise false

    - #### next

          public List<E> next()

      Returns the next permutation of the input collection.
      Specified by:
        `next` in interface `Iterator<List<E>>`
      Returns:
        a list of the permutator's elements representing a permutation
      Throws:
        `NoSuchElementException` - if there are no more permutations

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `Iterator<List<E>>`

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.