Java Program to check if a string is palindrome or not

In this tutorial, you will learn the writing program for how to check if a string is a palindrome in java .


Read This: What is String Palindrome? Write string palindrome program in C.

To check String is Palindrome or not?  This Program will take a String as an input. And after applying some logic it will return output as String is Palindrome or not.


For Example: 

Suppose if we give input a string “abba”. This is palindrome String then our program will print “string is palindrome”.

And if we give “abcd” then our program will give “String is not palindrome”.

Java program to check whether a string is palindrome or not

import java.util.*;  
public class Main {  
    public static void main(String[] args) {  
        Scanner sc= new Scanner(;
        System.out.print("Please give First String : ");  
        String str= sc.nextLine();  
        StringBuilder strRev = new StringBuilder();
        strRev = strRev.reverse(); 
            System.out.print("String is palindrom"); 
            System.out.print("String is not palindrom"); 


palindrome string program in java

Leave a Comment