Case Insensitive Palindrome Check
This program checks palindrome ignoring case.
Problem Statement
Write a Java program to check if a string is palindrome ignoring case.
Source Code
| 1 | public class CaseInsensitivePalindrome { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Case Insensitive Palindrome"); |
| 4 | String str="MadAm"; |
| 5 | String rev=new StringBuilder(str.toLowerCase()).reverse().toString(); |
| 6 | if(str.toLowerCase().equals(rev)) System.out.println("String is palindrome"); |
| 7 | else System.out.println("String is not palindrome"); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Case Insensitive Palindrome String is palindrome
Explanation
The string is converted to lowercase before reversing so that character case does not affect the comparison, demonstrating a case-insensitive palindrome check.