Fetching the code, complexity notes and tags. Just a moment.
This snippet checks whether a given string is a palindrome using the two-pointer technique. It compares characters from both ends of the string while moving toward the center. If all corresponding characters match, the string is a palindrome; otherwise, it is not. This approach is simple, efficient, and commonly asked in coding interviews.
Category
strings
Complexity
Time: O(n) | Space: O(1)
Language
Java
Status
Tags
Related Concepts
Published
Last Updated
Production-ready Java implementation for quick revision, interview preparation, and real-world development.
Solution.java
1public class PalindromeChecker {2 3 public static boolean isPalindrome(String str) {4 5 int left = 0;6 int right = str.length() - 1;7 8 while (left < right) {9 10 if (str.charAt(left) != str.charAt(right)) {11 return false;12 }13 14 left++;15 right--;16 }17 18 return true;19 }20 21 public static void main(String[] args) {22 23 String text = "madam";24 25 if (isPalindrome(text)) {26 System.out.println(text + " is a Palindrome.");27 } else {28 System.out.println(text + " is Not a Palindrome.");29 }30 }31}Keywords
Explore the important concepts and keywords associated with this Java snippet.
💡 These tags help you quickly identify the concepts covered in this snippet and make it easier to discover similar Java solutions throughout the library.