Hi All,

Greetings of the day!

Today we will learn how to check given String is Palindrome or not in Java so let's start.

What is Palindrome String

Palindrome String is a String that is the same when we read it from any end i.e. from start or end

Example ABBA 

How to check given String is Palindrome Or Not In Java

A simple way to check Palindrome String is to reverse a given string and then check if the original String and reversed string are equal or not. If both strings are equal we can say the given String is a Palindrome String.

So here is the sample code for the same.

  
package com.demo.programs;

public class CheckPalindrome {

    public static void main(String[] args) {
        String originalString="ABBA";
        String reverseString="";

        char[] chars=originalString.toCharArray();

        for(int i=chars.length-1;i>=0;i--){
            reverseString=reverseString+chars[i];
        }

        if(originalString.equalsIgnoreCase(reverseString)){
            System.out.println("Given String is palindrome");
        }else{
            System.out.println("Given String is not palindrome.");
        }
    }
}

To reverse a String we are using for loop over character array initialized from original String.

If you have any doubts about the above code feel free to comment, we will help you.

Other articles you can refer