ADVERTISEMENT
ADVERTISEMENT

Easiest way to check Given String is Palindrome String or not in Java

This java program will read a string and check whether it is Palindrome or not using easiest method.

package com.includehelp.stringsample;

import java.util.Scanner;

/**
 * Easiest way to check Given String is Palindrome String or not
 * @author includehelp
 */
public class PalindromString {
    
    static boolean isPalindromString(String inputStr){
        StringBuilder sb  = new StringBuilder(inputStr);
        String reverseStr = sb.reverse().toString();
 
        return (inputStr.equalsIgnoreCase(reverseStr));              
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter String : ");
        String inString = sc.next();
        
        if(isPalindromString(inString)){
            System.out.println(inString +" is a Palindrom String");
        }
        else{
            System.out.println(inString +" is not a Palindrom String");
        }
    }
}

Output

First run:
Enter String : india
india is not a Palindrom String

Second run:
Enter String : abcba
abcba is a Palindrom String

Java String Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.