- A palindrome is a word that reads the same backward or forward.
- Lets see what if the characters in a palindrome string are in different case. i.e should not be case sensitive.
- So now we will see how to check a string is palindrome or not by ignoring its case.
- Write a function which checks that string is palindrome or not by converting the original string to lowercase or uppercase.
- Method should return true if it is palindrome, return false if not a palindrome.
#1 : Java Program to check given string is palindrome or not by ignoring its case.
- package com.instanceofjava;
- public class CheckPalindrome {
- public static boolean isPalindrome(String str) {
- StringBuffer strone=new StringBuffer(str.toLowerCase());
- StringBuffer strtwo=new StringBuffer(strone);
- strone.reverse();
- System.out.println("Orginal String ="+strtwo);
- System.out.println("After Reverse ="+strone);
- if(String.valueOf(strone).compareTo(String.valueOf(strtwo))==0)
- return true;
- else
- return false;
- }
- public static void main(String[] args) {
- boolean ispalindrome= isPalindrome("DeleveleD");
- System.out.println(ispalindrome);
- }
- }
No comments