title: Finding palindrome String throws StringIndexOutOfBoundsException, possible cause?
body: <p>Provided a String, my objective is to check if I can make that String a palindrome string even after re-arranging the characters.</p>
  
  <p>For eg: <code>aaabbbb</code> can be made palindrome by changing to : <code>bbaaabb</code></p>
  
  <p>So what I did try is to compare all the permutations of the string with its reverse, if it exists, print a YES! . And here is the code so far:</p>
  
  <pre><code>private static void permutation(String prefix, String str)
  {
      temp.setLength(0); //temp is a StringBuilder
      int n = str.length();
      if((n==0) &amp;&amp; (str.charAt(0)==str.charAt(n-1)))
      {
          temp.append(prefix);
          temp.reverse();
          if(prefix.equals(temp.toString()))
          {
              System.out.println("YES");
              System.exit(0);
          }
      }
      else
      {
          for(int i=0;i&lt;n;i++)
              permutation(prefix+str.charAt(i),str.substring(0,i)+str.substring(i+1,n));
      }
  }
  </code></pre>
  
  <p>Now the problem is, at runtime I get a <strong>java.lang.StringIndexOutOfBoundsException</strong> at this line: <code>permutation(prefix+str.charAt(i),str.substring(0,i)+str.substring(i+1,n));</code></p>
  
  <p>What might be possibly causing this? </p>