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 looks like:
{1}
{2}
{3}
{1, 2}
{1, 3}
{2, 3}
{1, 2, 3}
What is the best (simplicity > efficiency in this case, the list won't be huge) way to implement this? Preferably in Java, but a solution in any language would be useful.
Use bitmasks:
Here are all bitmasks:
You know in binary the first bit is the rightmost.
A java solution based on Petar Minchev solution -
I've noticed that answers are focused on the String list. Consequently, I decided to share more generic answer. Hope it'll be fouund helpful. (Soultion is based on another solutions I found, I combined it to a generic algorithem.)
This is the simple function can be used to create a list of all the possible numbers generated by digits of all possible subsets of the given array or list.