I am looking for a way to iterate over all possibilites to split an array list into two array lists, where the first one has k elements and the second one has the rest.
For example, in Python I would write
import itertools
my_set = {1,2,3,4,5}
k = 2
map(lambda x: (set(x), my_set-set(x)), itertools.combinations(my_set, k))
which would give:
[(set([1, 2]), set([3, 4, 5])),
(set([1, 3]), set([2, 4, 5])),
(set([1, 4]), set([2, 3, 5])),
(set([1, 5]), set([2, 3, 4])),
(set([2, 3]), set([1, 4, 5])),
(set([2, 4]), set([1, 3, 5])),
(set([2, 5]), set([1, 3, 4])),
(set([3, 4]), set([1, 2, 5])),
(set([3, 5]), set([1, 2, 4])),
(set([4, 5]), set([1, 2, 3]))]
How can I get all k-element subsets of a given set (well, ArrayList) in Java?