Java program to check whether string is palindrome using library methods

Let’s learn java program to check whether string is palindrome using library methods.

Java program to check whether string is palindrome using library methods

java program to check whether string is palindrome using library methods

Check if a string is a palindrome java is the common java interview question.

Palindrome string is a string which is same even if it is reversed. For example, eye, malayalam, abcba etc.,

// string palindrome in java
public class StringPalindromeJava
{
   // ispalindrome java
   public static void isPalindrome(String str)
   {
      String strReverse = new StringBuffer(str).reverse().toString();
       // checking for palindrome
      if(str.equals(strReverse))
      {
         System.out.println(str + " is palindrome string.");
      }
      else
      {
         System.out.println(str + " is not palindrome string.");
      }
   }

   public static void main(String[] args)
   {
      // palindrome java
      isPalindrome("eye");
      isPalindrome("rotator");
   }
}



Output:

eye is palindrome string.
flowerbrackets is not palindrome string.

Also read – multidimensional array in java