- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find if a string is a palindrome using Java?
StringBuffer provides a method with name reverse() one way to check for a palindrome is
- Create a StringBuffer object by passing the required string as a parameter to the constructor.
- Reverse the contents of the object using the reverse() method.
- Convert the StringBuffer object to Sting using the toString() method.
- Now, compare the String and the reversed one, if true, the given string is a palindrome.
Example
public class StringPalindrome { public static void main(String args[]){ String myString = "anna"; StringBuffer buffer = new StringBuffer(myString); buffer.reverse(); String data = buffer.toString(); if(myString.equals(data)){ System.out.println("Given String is palindrome"); }else{ System.out.println("Given String is not palindrome"); } } }
Output
Given String is palindrome
- Related Articles
- How to check if String is Palindrome using C#?
- How to check a String for palindrome using arrays in java?
- Check if a string is palindrome in C using pointers
- JavaScript - Find if string is a palindrome (Check for punctuation)
- C Program to Check if a Given String is a Palindrome?
- Write an example to find whether a given string is palindrome using recursion
- How to Check Whether a String is Palindrome or Not using Python?
- C# program to check if a string is palindrome or not
- Python program to check if a string is palindrome or not
- Python program to check if a given string is number Palindrome
- Recursive function to check if a string is palindrome in C++
- How to check Palindrome String in java?
- Java program to print whether the given string is a palindrome
- How to check if a string is palindrome or not without filters in VueJs?
- TCP Client-Server Program to Check if a Given String is a Palindrome

Advertisements