public static > LinkedList> BinPowSet( LinkedList A){ LinkedList> ans= new LinkedList>(); int ansSize = (int)Math.pow(2, A.size()); for(int i= 0;i< ansSize;++i){ String bin= Integer.toBinaryString(i); //convert to binary while(bin.length() < A.size()) bin = "0" + bin; //pad with 0's LinkedList thisComb = new LinkedList(); //place to put one combination for(int j= 0;j< A.size();++j){ if(bin.charAt(j) == '1')thisComb.add(A.get(j)); } Collections.sort(thisComb); //sort it for easy checking ans.add(thisComb); //put this set in the answer list } return ans; }