String Palindrome in Java: Explanation & Practice

Check if a string is a palindrome

Problem summary

Write a program that checks if a string is a palindrome (reads same forwards and backwards).

Starter code

public class Main {
    public static void main(String[] args) {
        String text = "madam"; // Test case 1
        
        // Check if palindrome (ignore case)
        // Print: Is palindrome: <true/false>
    }
}

Expected output and test cases

  • madam is palindrome
    Is palindrome: true
  • Racecar (ignore case)
    Is palindrome: true
  • Hello is not
    Is palindrome: false

Hints

  1. Compare characters from both ends
  2. Use toLowerCase() for case-insensitive
  3. Or reverse and compare with original

Related Strings exercises

Practice all Strings exercises · Run this idea in the Java compiler