Java program to check whether a string is a Palindrome
A string is said to be a palindrome if it is the same if we start reading it from left to right or right to left. So let us consider a string “str”, now the task is just to find out with its reverse string is the same as it is.
Input : str = "abba" Output: Yes
Input : str = "geeks" Output: No
Approach: Our approach will be that initially, we will take two pointers i pointing to the start of the string and j pointing to the end of the string. Keep incrementing i and decrementing j while i < j and at every step check whether the characters at these pointers are same or not. If not then the string is not a palindrome else it is.
String 1 :It is not a pallindrome String 1 :It is a pallindrome
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.