title: Java - Finding all subsets of a String (powerset) recursively
body: <p>So, I need to find all subsets of a given string recursively. What I have so far is:</p>
  
  <pre><code>static ArrayList&lt;String&gt; powerSet(String s){
          ArrayList&lt;String&gt; ps = new ArrayList&lt;String&gt;();
          ps.add(s);
  
  
          for(int i=0; i&lt;s.length(); i++){
              String temp = s.replace(Character.toString(s.charAt(i)), "");
              ArrayList&lt;String&gt; ps2 = powerSet(temp);
              for(int j = 0; j &lt; ps2.size(); j++){
                  ps.add(ps2.get(j));
              }
          }   
  
          return ps;
  </code></pre>
  
  <p>I think I know what the problem is now, but I dont know how to fix it. Currently, I find all the power sets of temp, which are "bcd", "acd", "abd", "abc", which will cause duplicates. Any ideas on how to fix this? </p>
  
  <p>By powerset, I mean if the string is abc, it will return  "", "a", "b", "c", "ab", "ac", "bc", "abc".</p>