public static <E extends Comparable<? super E>> Collection<List<E>> orderedPermutations(Collection<E> elements) {
        return orderedPermutations(elements, Comparators.naturalOrder());
    }
public static < E extends Comparable < ? super E > > Collection < List < E > > orderedPermutations ( Collection < E > elements ) { return orderedPermutations ( elements , Comparators . naturalOrder ( ) ) ; }
Note: copy from Google Guava under Apache License v2.
<br />

Returns a {@link Collection} of all the permutations of the specified
{@link Iterable}.

<p><i>Notes:</i> This is an implementation of the algorithm for
Lexicographical Permutations Generation, described in Knuth's "The Art of
Computer Programming", Volume 4, Chapter 7, Section 7.2.1.2. The
iteration order follows the lexicographical order. This means that
the first permutation will be in ascending order, and the last will be in
descending order.

<p>Duplicate elements are considered equal. For example, the list [1, 1]
will have only one permutation, instead of two. This is why the elements
have to implement {@link Comparable}.

<p>An empty iterable has only one permutation, which is an empty list.

<p>This method is equivalent to
{@code Collections2.orderedPermutations(list, Ordering.natural())}.

@param elements the original iterable whose elements have to be permuted.
@return an immutable {@link Collection} containing all the different
permutations of the original iterable.
@throws NullPointerException if the specified iterable is null or has any
null elements.