```
public ArrayList<ArrayList<Integer>> subsets(int[] S) {
return subsetsHelper1(S, 0);
}
private ArrayList<ArrayList<Integer>> subsetsHelper1(int[] S, int index) {
ArrayList<ArrayList<Integer>> allSubsets = new ArrayList<ArrayList<Integer>>();
int len = S.length;
if (len == 0)
return allSubsets;
if (index == len) {
allSubsets.add(new ArrayList<Integer>());
return allSubsets;
} else {
ArrayList<ArrayList<Integer>> curSubsets = subsetsHelper1(S, index + 1);
allSubsets.addAll(curSubsets);
int curVal = S[index];
for (int i = 0; i < curSubsets.size(); i++) {
ArrayList<Integer> set = curSubsets.get(i);
set.add(0, curVal);
}
allSubsets.addAll(curSubsets);
return allSubsets;
}
}
```