---
title: "Write code to check a String is palindrome or not?"  
description: "Write code to check a String is palindrome or not?"  
author: "Ronan Jone"  
published: 2018-02-27  
canonical: https://answers.mindstick.com/qa/35069/write-code-to-check-a-string-is-palindrome-or-not  
category: "programming"  
reading_time: 1 minute  

---

# Write code to check a String is palindrome or not?

## Answers

### Answer by Arti Mishra

A [string](https://www.mindstick.com/articles/1717/string-string-builder-and-string-buffer-in-java) is a palindrome if it remains unchanged when reversed, for example, "dad" is a palindrome as [reverse](https://www.mindstick.com/forum/1603/java-reverse-selection-sort) of "dad" is "dad" whereas "parents" is not a palindrome as its reverse is “stnerap”.

[Program to Check](https://www.mindstick.com/forum/156853/write-a-c-sharp-program-to-check-given-number-is-armstrong-or-not) enter String is palindrome or not

| [import](https://www.mindstick.com/blog/294/how-to-import-or-export-sql-server-table-data-in-ms-excel-sheet-using-c-sharp-code) java.util.*; \ [class](https://www.mindstick.com/articles/12089/arrays-in-java-determining-class-of-an-array-part-8) PalindromeExample \ { \ [public](https://www.mindstick.com/interview/757/why-main-in-java-is-declared-as-public-static-void-main) [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) void main(String args[]) \ { \ String str, reverse = ""; \ [Scanner](https://www.mindstick.com/forum/33502/java-scanner-issue-why-input-is-skipped-when-using-next-nextint-etc-after-nextline) sc = new Scanner(System.in); \ \ System.out.println("Enter a string to [check if](https://www.mindstick.com/forum/23208/check-if-a-file-exists-using-python) it is a palindrome"); \ str = sc.nextLine(); \ \ int [length](https://www.mindstick.com/interview/1915/what-is-the-difference-between-char_length-and-length) = str.length(); \ \ for ( int i = length - 1; i >= 0; i-- ) \ reverse = reverse + str.charAt(i); \ \ if (str.equals(reverse)) \ System.out.println("Entered string is a palindrome."); \ else \ System.out.println("Entered string is not a palindrome."); \ } \ } \ \ |
| --- |

\
\


---

Original Source: https://answers.mindstick.com/qa/35069/write-code-to-check-a-string-is-palindrome-or-not

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
