how to check the number is palindrome or not in java8 code example
Example 1: 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();
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");
}
}
Example 2: integer palindrome in java
public boolean isPalindrome(int x) {
String str = Integer.toString(x);
String reverse = new StringBuilder(str).reverse().toString();
return str.equals(reverse)?true:false;
}