posted 3 months ago
The size is the length of the original set. so having the subset {1, 2, 3, 4} the size would have to be at least 6, which would deliver the new subset (1, 2, 3, 4, 5}.

The idea is that, recursively, I start with subsets of length 0, being a List of just the empty List. Then, generating the subsets of length 1, starting from all the subsets of length 0, I have

IntStream(list.isEmpty? 0 : Collections.max + 1, size), so that if the original set is {0, 1, 2, ..., 9}, then size = 10 and I would get Intstream.range(0, 10), et cetera.

As said, I liked this implementation, but there are many other ways.

Having all the subsets of the List {0, 1, 2, ... N}, it is then easy to map the integers 0...N to the elements of an arbitrary List<T>, so that you can easily generate all subsets of that list, and it doesn't matter if that list contains duplicates or not. Efficient? Never tested for that, but short and easy? Yes.

Edit: the method I supplied ir\s only one of the two methods I use, in the other method the size is determined.