我如何编码它遍历列表并生成TRUE FALSE TRUE
randomphrase = ['lanal', 'samuel is my cat', 'too hot to hoot']
print(is_palindrome(randomphrase))
import java.util.ArrayList;
import java.util.Arrays;
public class StackOverflow {
public static void main(String args[]) {
ArrayList<String> randomPhrases = new ArrayList<>(Arrays.asList("lanal", "samuel is a cat", "too hot to hoot"));
// I loop through the list and check if each string is a palindrome
for (String str : randomPhrases) {
isPalindrome(str);
}
}
private static boolean isPalindrome(String str) {
//test for end of recursion
if (str.length() < 2) {
System.out.println("true");
return true;
}
//check first and last character for equality
if (str.charAt(0) != str.charAt(str.length() - 1)) {
System.out.println("false");
return false;
}
//recursion call
return isPalindrome(str.substring(1, str.length() - 1));
}
}