We need to write a java program to check whether the given string is palindrome or not.

We can check a palindrome string in java in three ways.

Check Palindrome String in Java using Reverse

In this method first, we will reverse the string and then will compare it with the original input string. To reverse the string we need to loop through each character of the original string from the back and concatenate into the reverse string.

Output

Check Palindrome String in Java Without Reverse

To check whether a string or word is palindrome or not without computing reverse, we need to compare 1st half of the string with another half. We can achieve this by using for loop from 0 to half the length of input string (i.e str.length()/2).

Output

Check Palindrome String in Java Without Loop

Java has StringBuilder class, which can be used to reverse a string using inbuilt reverse() method.

Output

If you have any doubts or problem with the solution, comment below.

Leave a Reply

Close Menu