fork download
  1. class PalindromeTest {
  2. public static void main (String[] args) {
  3.  
  4. String str = "abcdcba";
  5. boolean palindrome = str.contentEquals(new StringBuilder(str).reverse());
  6. System.out.println(palindrome); // prints true
  7.  
  8. str = "abcd";
  9. palindrome = str.contentEquals(new StringBuilder(str).reverse());
  10. System.out.println(palindrome); // prints false
  11.  
  12. }
  13. }
Success #stdin #stdout 0.05s 27788KB
stdin
Standard input is empty
stdout
true
false