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

Palindrome string program in java is the common java interview question.

java program to check whether string is palindrome using library methods

Palindrome string is a string which is same even if it is reversed. For example,

eye, malayalam, abcba etc.,

Here’s the java program to check whether string is palindrome using library methods.

public class StringPalindromeJava
{
   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 – abstraction in java