// Check for palindromes ignoring non-alphanumeric. // Book does it using StringBuilder // This is the "equivalent" String-only soln. // The real difference is my append vs Stringbuilder's append // I use string concatination, which involves copying so is less efficient import java.util.Scanner; public class PalindromeOnlyAlpha { public static void main (String[] args) { Scanner getInput = new Scanner(System.in); System.out.print("Enter a string: "); String s = getInput.nextLine(); System.out.printf("%s\nis %s a palindrome? %s\n", "Ignoring nonalpnumeric characters,", s, isPalindrome(s)); } public static boolean isPalindrome(String s) { String s1 = filter(s); String s2 = reverse(s1); return s2.equals(s1); } public static String filter(String s) { String answer = new String(); for (int i=0; i