Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 545 Bytes

check-palindrome.md

File metadata and controls

20 lines (17 loc) · 545 Bytes
title description author tags
Check Palindrome
Checks if a string reads the same backward as forward, ignoring whitespaces and case sensitivity
Mcbencrafter
string,palindrome,compare,reverse
public static boolean isPalindrome(String text) {
    String cleanText = text.toLowerCase().replaceAll("\\s+", "");
        
    return new StringBuilder(cleanText)
            .reverse()
            .toString()
            .equals(cleanText);
}

// Usage:
System.out.println(isPalindrome("A man a plan a canal Panama")); // true