Question

I'm searching for a library (preferably generic) that generates iterable combinations and permutations of data contained in collections. Cartesian product would also be nice.

The best way of describing what I want would be "itertools for Java".

Was it helpful?

Solution

itertools does much more than just combinations and permutations, so (while it would surely be nice to have all of itertools when coding Java;-) you can get away with much less.

For example, for permutations, see here; for combinations, here (both classes are from the same author).

OTHER TIPS

I'm actually making a port of itertools to java: it's called neoitertools

Any feedback appreciated as it still in beta. Missing the "product" function yet, and some intensive tests.

Here you find something that might cover your combinatorial needs bundled in a library:

http://code.google.com/p/combinatoricslib/

I'm just throwing this out there, but shouldn't it be possible to use Python's itertools implementation directly from Java using Jython? Is it a C-based api?

[one Google later]

itertools (Jython API documentation)

Actually, the neoitertools project listed above looks very promising, it appears to be in [very] active development (according to Google code) and looks to be a complete implemetation of the itertools functionality, plus it's available via Maven.

Just my 2 pence.

Few years later, combinatorics seems to fit your needs. Taken from the readme:

Simple permutations
Permutations with repetitions
Simple combinations
Combinations with repetitions
Subsets
Integer Partitions
List Partitions
Integer Compositions
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top