I have a List of elements (1, 2, 3), and I need to get the superset (powerset) of that list (without repeating elements). So basically I need to create a List of Lists that
Peter Minchev's solution modified to handle larger lists through BigInteger
public static List> getAllSubsets(List input) {
BigInteger allMasks = BigInteger.ONE.shiftLeft(input.size());
List> output = new ArrayList<>();
for(BigInteger i=BigInteger.ZERO;allMasks.subtract(i).compareTo(BigInteger.ZERO)>0; i=i.add(BigInteger.ONE)) {
List subList = new ArrayList();
for(int j=0;j 0) {
subList.add(input.get(j));
}
}
System.out.println(subList);
output.add(subList);
}
return output;
}