It does not happen often, but once in a while you want to generate all possible permutations of a list of Objects.

In a particular case I wanted to generate all possible permutations by swapping two direct neighbours in a list. I found Even's speedup of the Steinhaus Johnson Trotter algorithm

This project contains a Java implementation of that algorithm. It contains an Iterator that generates Swap objects. Each Swap object has a left and a right element that are neighbours of each other in the permutation generated before that. So:

If you have a list [A, B, C] it will generate Swap(C, B)
Applying this Swap to the original list will result in [A, C, B]
Then the Iterator will generate Swap(A,C)
Applying this to the previous permutations results in [C, A, B]
Then comes Swap(A,B)
Result: [C, B, A]
Then Swap(C, B) -> [B, C, A]
Then Swap(A, C) -> [B, A, C]
done.

After I implemented this Swap generating Iterator it was simple to create an Iterator that just generates all possible permutations that adheres to the rule that only neighbouring elements will be swapped.

Both Iterators have a generic type, so you can supply it with lists of any type that you would need.

Have a look at the files section. There is a jar that can be used. The jar also contains the source code.