views:

179

answers:

2

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".

+1  A: 

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).

Alex Martelli
Thanks, probably I'll adapt something from the links you shared. I also agree that it would be great to have all of itertools.
Fabio de Miranda
@Fabio, I agree. Shouldn't be _too_ hard to write, either -- if I had to use Java often (currently I don't), I'd seriously consider doing that.
Alex Martelli
+1  A: 

Cartesian product is available here: http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Sets.html#cartesianProduct%28java.util.Set...%29

Kevin Bourrillion
Thanks, I'll check it out. The design based on generics may help me solve my problem.
Fabio de Miranda