title: Palindrome Checker using StringBuilder
body: <p>Im trying to create a palindrome checker. I am using a StringBuilder and I've discovered that appending spaces are kind of tricky.</p>
  
  <h2>EDIT: are there other ways besides using .reverse()? Thanks for the answers. :D</h2>
  
  <p>This code works when the word has no spaces:</p>
  
  <pre><code>public String palindrome (String anyString) {
  
  StringBuilder sb = new StringBuilder();
  
  for (int i = anyString.length()-1; i&gt;=0; i--) {
          sb.append(anyString.charAt(i));
  }
  
  String string2 = sb.toString();
  
  return string2;
  }
  </code></pre>
  
  <p>When the word entered has a space; it returns a string that includes characters up to the first space.</p>
  
  <p>E.g.:</p>
  
  <pre><code>word = "not a palindrome"
  palindrome(word) = "emordnilap"
  </code></pre>
  
  <p><em><strong>expected</em></strong> = "emordnilap a ton"</p>
  
  <hr>
  
  <p>I have tried inserting</p>
  
  <pre><code>if (anyString.charAt(i) != ' ')
      sb.append(anyString.charAt(i));
  else 
      sb.append(' ');
  </code></pre>
  
  <p>at the middle of the code but it doesn't work.</p>
  
  <p>Thanks guys!</p>