Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Write a method to check if input String is Palindrome?

Category: Java

A String is said to be Palindrome if its value is same when reversed. For example “aba” is a Palindrome String.
String class doesn’t provide any method to reverse the String but StringBuffer and StringBuilder class has reverse method that we can use to check if String is palindrome or not.
private static boolean isPalindrome(String str) {
if (str == null)
return false;
StringBuilder strBuilder = new StringBuilder(str);
strBuilder.reverse();
return strBuilder.toString().equals(str);
}

Leave a Reply

Your email address will not be published. Required fields are marked *