title: How to find permutations of a string with all distinct characters?
body: <p>I have found a piece of code in a book which claims to print all permutations of a string with all distinct characters :-</p>
  <pre><code>void permutation(String str) {
      permutation(str, &quot;&quot;);
  }
      
  void permutation(String str, String prefix) {
      if (str.length() == 0) {
          System.out.println(prefix);
      } else {
          for (int i = 0; i &lt; str.length(); i++) {
              String rem = str.substring(0, i) + str.substring(i + 1);
              permutation(rem, prefix + str.charAt(i));
          }
      }
  }
  </code></pre>
  <p>What is the role of the rem variable in the code?</p>