A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.
To check whether a word is a palindrome I get th
- This implementation works for numbers and strings.
- Since we are not writing anything, so there is no need to convert the string into the character array.
public static boolean isPalindrome(Object obj)
{
String s = String.valueOf(obj);
for(int left=0, right=s.length()-1; left < right; left++,right--)
{
if(s.charAt(left++) != s.charAt(right--))
return false;
}
return true;
}