Recursive Function : Check for palindrome in Java
I have a class that checks whether a string is a palindrome or not. I have two questions. 1) Is this the most efficient way to check for palindrome? 2) Can this be implemented recursively? 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; } } } 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...