Palindrome program in java using library methods

Hey guys!! Welcome to flower brackets blog. In this post let’s learn palindrome program in java using library methods.

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

Related Posts