class PalindromeTest {
public static void main
(String[] args
) {
boolean palindrome = str.contentEquals(new StringBuilder(str).reverse());
System.
out.
println(palindrome
); // prints true
str = "abcd";
palindrome = str.contentEquals(new StringBuilder(str).reverse());
System.
out.
println(palindrome
); // prints false
}
}
Y2xhc3MgUGFsaW5kcm9tZVRlc3QgewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHsKCQkKCQlTdHJpbmcgc3RyID0gImFiY2RjYmEiOwoJCWJvb2xlYW4gcGFsaW5kcm9tZSA9IHN0ci5jb250ZW50RXF1YWxzKG5ldyBTdHJpbmdCdWlsZGVyKHN0cikucmV2ZXJzZSgpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4ocGFsaW5kcm9tZSk7ICAvLyBwcmludHMgdHJ1ZQoJCQoJCXN0ciA9ICJhYmNkIjsKCQlwYWxpbmRyb21lID0gc3RyLmNvbnRlbnRFcXVhbHMobmV3IFN0cmluZ0J1aWxkZXIoc3RyKS5yZXZlcnNlKCkpOwoJCVN5c3RlbS5vdXQucHJpbnRsbihwYWxpbmRyb21lKTsgIC8vIHByaW50cyBmYWxzZQoJCQoJfQp9