I am trying to do a homework in math which is find a subset of collection {1,2,..,n} where n is a number given in the code, I cannot get it done with the sublist so I need to get your help with a math programming.

For example for n = 2:

```
[12]
[1][2]
```

It have 2 elements.

For example for n = 3:

```
[1][2][3]
[12][3]
[13][2]
[23][1]
[123]
```

It have 5 elements.

It have five elements.

For n = 4:

```
[1][2][3][4]
[12][3][4]
[13][2][4]
[14][2][3]
[23][1][4]
[24][1][3]
[34][1][2]
[12][34]
[13][24]
[14][23]
[123][4]
[124][3]
[134][2]
[234][1]
[1234]
```

It have **15** elements.

Do you have any ideas how to get it done?

I have tried many possibilites with LinkedHashSet and sublist inside loop but I had no clue for over 2h how to get it done, the output like this.

Is there any library in the Java to get this output? I would do that by manuall way, but there ahve to be different way.

```
import org.paukov.combinatorics.*;
import org.paukov.combinatorics.util.ComplexCombinationGenerator;
public class Main {
public static void main(String args[]){
// create a vector (A, B, B, C)
ICombinatoricsVector<String> vector = Factory.createVector(new String[] { "1", "2", "3"});
// Create a complex-combination generator
Generator<ICombinatoricsVector<String>> gen = new ComplexCombinationGenerator<String>(vector, 1);
Generator<ICombinatoricsVector<String>> gen2 = new ComplexCombinationGenerator<String>(vector, 2);
Generator<ICombinatoricsVector<String>> gen3 = new ComplexCombinationGenerator<String>(vector, 3);
// Iterate the combinations
for (ICombinatoricsVector<ICombinatoricsVector<String>> comb : gen) {
System.out.println(ComplexCombinationGenerator.convert2String(comb) + " - " + comb);
}
for (ICombinatoricsVector<ICombinatoricsVector<String>> comb : gen2) {
System.out.println(ComplexCombinationGenerator.convert2String(comb) + " - " + comb);
}
for (ICombinatoricsVector<ICombinatoricsVector<String>> comb : gen3) {
System.out.println(ComplexCombinationGenerator.convert2String(comb) + " - " + comb);
}
}
}
([1, 2, 3]) - CombinatoricsVector=([CombinatoricsVector=([1, 2, 3], size=3)], size=1)
([1],[2, 3]) - CombinatoricsVector=([CombinatoricsVector=([1], size=1), CombinatoricsVector=([2, 3], size=2)], size=2)
([2, 3],[1]) - CombinatoricsVector=([CombinatoricsVector=([2, 3], size=2), CombinatoricsVector=([1], size=1)], size=2)
([2],[1, 3]) - CombinatoricsVector=([CombinatoricsVector=([2], size=1), CombinatoricsVector=([1, 3], size=2)], size=2)
([1, 3],[2]) - CombinatoricsVector=([CombinatoricsVector=([1, 3], size=2), CombinatoricsVector=([2], size=1)], size=2)
([1, 2],[3]) - CombinatoricsVector=([CombinatoricsVector=([1, 2], size=2), CombinatoricsVector=([3], size=1)], size=2)
([3],[1, 2]) - CombinatoricsVector=([CombinatoricsVector=([3], size=1), CombinatoricsVector=([1, 2], size=2)], size=2)
([1],[2],[3]) - CombinatoricsVector=([CombinatoricsVector=([1], size=1), CombinatoricsVector=([2], size=1), CombinatoricsVector=([3], size=1)], size=3)
([1],[3],[2]) - CombinatoricsVector=([CombinatoricsVector=([1], size=1), CombinatoricsVector=([3], size=1), CombinatoricsVector=([2], size=1)], size=3)
([3],[1],[2]) - CombinatoricsVector=([CombinatoricsVector=([3], size=1), CombinatoricsVector=([1], size=1), CombinatoricsVector=([2], size=1)], size=3)
([3],[2],[1]) - CombinatoricsVector=([CombinatoricsVector=([3], size=1), CombinatoricsVector=([2], size=1), CombinatoricsVector=([1], size=1)], size=3)
([2],[3],[1]) - CombinatoricsVector=([CombinatoricsVector=([2], size=1), CombinatoricsVector=([3], size=1), CombinatoricsVector=([1], size=1)], size=3)
([2],[1],[3]) - CombinatoricsVector=([CombinatoricsVector=([2], size=1), CombinatoricsVector=([1], size=1), CombinatoricsVector=([3], size=1)], size=3)
```