coderolls Staff
coderolls Staff Hi 👋🏼, At coderolls we write tutorials about Java programming language and related technologies.

Java Program To Check If the given String Is Palindrome or Not

In this tutorial, we will see a Java program to check if the given String is palindrome or not.

Java Program To Check If the given String Is Palindrome or Not

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * A Java program to check if the given string is palindrome or not.
 * @author coderolls.com
 */
public class PalindromeString {

    public static void main(String[] args) {
        String str1 = "racecar";
        checkIfPalindrome(str1);
    }

    private static void checkIfPalindrome(String str) {
        String reversedString = "";
        int len = str.length();
        for (int i = (len - 1); i >= 0; --i) {
            reversedString = reversedString + str.charAt(i);
        }
        if (str.equalsIgnoreCase(reversedString)) {
            System.out.println("The String '" + str + "' is a Palindrome String.");
        } else {
            System.out.println("The String '" + str + "' is not a Palindrome String.");
        }
    }
}

Output

1
The String 'racecar' is a Palindrome String.
Join Newsletter
Get the latest tutorials right in your inbox. We never spam!

comments powered by Disqus