How to check palindrome string in Java ?

Before we start to check that given string is palindrome or not lets first understand the palindrome term.
If you reverse the given string and you get the same value as of your string has then that string is palindrome.
For example - "ABBA" and if you reverse it then you will get the same i.e "ABBA".

Now lets check the coding part.

package com.infybuzz.string;

public class PalindromeString {

 public static void main(String[] args) {
  String str1 = "Hello infybuzz";
  String str2 = "abccba";
  System.out.println(str1 + " " + checkPalindrome(str1));
  System.out.println(str2 + " " + checkPalindrome(str2));
 public static String checkPalindrome(String str1) {
  StringBuilder stringBuilder = new StringBuilder(str1);
  String str2 = stringBuilder.reverse().toString();
  if (str1.equals(str2)) { // equalsIgnoreCase can be used as well
   return "is Palindrome";
  } else {
   return "is NOT Palindrome";



Hello infybuzz is NOT Palindrome
abccba is Palindrome

More ways to reverse a string in Java