Java program to check palindrome using library methods

In this post let’s learn java program to check palindrome using library methods.

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.,

public class JavaPalindrome
{
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)
{
isPalindrome("eye");
isPalindrome("rotator");
}
}

Output:

eye is palindrome string.
flowerbrackets is not palindrome string.

Also read – palindrome string in java without reversing a string