Ad space (banner)
โ˜•Java Lessons
Lesson 43 / 68

Reversing a String and Checking for Palindromes

This lesson covers reversing a string and checking whether it's a palindrome in Java, so you understand the basics of string manipulation. It's for anyone searching "Java string reversal palindrome check."

StringBuilder's .reverse() reverses a string. A string that reads the same forward and backward is called a palindrome.

The example reverses a string with new StringBuilder(s).reverse().toString() inside an isPalindrome() method, then compares it to the original string s with .equals(). "racecar" reads the same backward, so it's correctly identified as a palindrome.

A common early mistake is not knowing Java's String has no direct .reverse() method of its own. You need to convert it to a StringBuilder to reverse it โ€” something that trips people up if they don't already know it.

It's a classic exercise for practicing how to think about string manipulation in general.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Java directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)