Possible Duplicate:
Check string for palindrome
Hello experts. I am asked, if it is possible to find whether a string is palidrome of another string in just one line of code in C++/Java.
If yes, then how?
Can any one answer. Thnx for ur view.
Possible Duplicate:
Check string for palindrome
Hello experts. I am asked, if it is possible to find whether a string is palidrome of another string in just one line of code in C++/Java.
If yes, then how?
Can any one answer. Thnx for ur view.
In Java, String
does not have a reverse
method. StringBuilder
has though, so you can still do it in one line:
boolean palindrome = str.contentEquals(new StringBuilder(str).reverse());
Reverse the string using reverse and then compare with original string.
String str="ABBA"
if(str.COmpareTo(str.reverse()) ==0)
//String is palindrome.