I would like to know how to calculate all possible combinations in a given arraylist? E.g
ArrayList contains following elements {1, 2, 3}
. now the following combinations should be generated
{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}
I would like to know how to calculate all possible combinations in a given arraylist? E.g
ArrayList contains following elements {1, 2, 3}
. now the following combinations should be generated
{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}
You can see each element in array list as a bit and implement a binary counter . The count gives you all the sets . You have 1, 2 ,3 in arraylist , lets visualize them as 3 bits for a while . 000, 001, 010, 011, 100, 101, 110,111 gives you the power set. All you need to is implement a binary counter , which is trivial.