Search code examples
javac++palindrome

Check palindrome in C++/Java


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.


Solution

  • 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());
    

    Ideone.com demo