title: Recursive Function : Check for palindrome in Java
body: <p>I have a class that checks whether a string is a palindrome or not. I have two questions. </p>
  
  <p>1) Is this the most efficient way to check for palindrome? 
  2) Can this be implemented recursively?</p>
  
  <pre><code>public class Words {
  
      public static boolean isPalindrome(String word) {
      String pal = null;
      word = word.replace(" ", "");
      pal = new StringBuffer(word).reverse().toString();
      if (word.compareTo(pal) == 0) {
          return true;
      } else {
          return false;
      }
  
      }
  
  }
  </code></pre>
  
  <p>Have a test class to test this... Doubt its needed but here it is anyways if anyone cares to try it out to be able to help me with any of the two questions above...</p>
  
  <pre><code>public class testWords {
  
      public static void main(String[] args) {
      if (Words.isPalindrome("a") == true) {
          System.out.println("true");
      } else {
          System.out.println("false");
      }
      if (Words.isPalindrome("cat") == true) {
          System.out.println("true");
      } else {
          System.out.println("false");
      }
      if (Words.isPalindrome("w o    w") == true) {
          System.out.println("true");
      } else {
          System.out.println("false");
      }
      if (Words.isPalindrome("   a  ") == true) {
          System.out.println("true");
      } else {
          System.out.println("false");
      }
      if (Words.isPalindrome("mom!") == true) {
          System.out.println("true");
      } else {
          System.out.println("false");
      }
  
      }
  
  }
  </code></pre>
  
  <p>thanks in advance for any help and or input :)</p>