JavaBeginner#strings

How do you check if a String is a palindrome?

Compare the string to its reverse, or use two pointers moving from both ends toward the middle, checking character equality at each step.

Example
boolean isPalindrome(String s) {
  int i = 0, j = s.length() - 1;
  while (i < j) { if (s.charAt(i++) != s.charAt(j--)) return false; }
  return true;
}
isPalindrome("madam"); // true

Related Questions

1
JavaBeginner#strings

What is the difference between String.format and concatenation?

Open
2
JavaIntermediate#strings

How do you split a String and handle edge cases with delimiters that are regex special characters?

Open
3
JavaIntermediate#collections

What is the difference between Set implementations HashSet, LinkedHashSet, and TreeSet?

Open