Determine whether a string is a palindrome? : String equal « Data Type « Java






Determine whether a string is a palindrome?

 
 
public class Main {
  static boolean isPalindrome(String text) {
    System.out.println("Original text = " + text);

    String reverse = new StringBuilder(text).reverse().toString();
    System.out.println("Reverse text  = " + reverse);
    return text.equalsIgnoreCase(reverse);
  }

  public static void main(String[] args) {
    String text = "Sator Arepo Tenet Opera Rotas";

    System.out.println("Is Palindrom: " + isPalindrome(text));
  }
}

   
  








Related examples in the same category

1.String: equalString: equal
2.Check string for equality