Repository: TheAlgorithms/Java
Pull request #3643 (2022-10-23 19:37:34)

Fixed error in Palindrome.java and gave semantic names to functions
<!-- For completed items, change [ ] to [x] -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Java files are placed inside an existing directory.
- [x] All filenames are in all uppercase characters with no spaces or dashes.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [x] If this pull request resolves one or more open issues then the commit message contains `Fixes: #{$ISSUE_NO}`.



Patch:
diff --git a/src/main/java/com/thealgorithms/strings/Palindrome.java b/src/main/java/com/thealgorithms/strings/Palindrome.java
index 30a7e08d..0046e545 100644
--- a/src/main/java/com/thealgorithms/strings/Palindrome.java
+++ b/src/main/java/com/thealgorithms/strings/Palindrome.java
@@ -6,26 +6,7 @@ package com.thealgorithms.strings;
 class Palindrome {
 
     /**
-     * Driver Code
-     */
-    public static void main(String[] args) {
-        String[] palindromes = { null, "", "aba", "123321" };
-        for (String s : palindromes) {
-            assert isPalindrome(s) &&
-            isPalindromeRecursion(s) &&
-            isPalindrome1(s);
-        }
-
-        String[] notPalindromes = { "abb", "abc", "abc123" };
-        for (String s : notPalindromes) {
-            assert !isPalindrome(s) &&
-            !isPalindromeRecursion(s) &&
-            !isPalindrome1(s);
-        }
-    }
-
-    /**
-     * Check if a string is palindrome string or not
+     * Check if a string is palindrome string or not using String Builder
      *
      * @param s a string to check
      * @return {@code true} if given string is palindrome, otherwise
@@ -54,17 +35,17 @@ class Palindrome {
             return false;
         }
 
-        return isPalindrome(s.substring(1, s.length() - 1));
+        return isPalindromeRecursion(s.substring(1, s.length() - 1));
     }
 
     /**
-     * Check if a string is palindrome string or not another way
+     * Check if a string is palindrome string or not using two pointer technique
      *
      * @param s a string to check
      * @return {@code true} if given string is palindrome, otherwise
      * {@code false}
      */
-    public static boolean isPalindrome1(String s) {
+    public static boolean isPalindromeTwoPointer(String s) {
         if (s == null || s.length() <= 1) {
             return true;
         }


Test patch:
diff --git a/src/test/java/com/thealgorithms/strings/PalindromeTest.java b/src/test/java/com/thealgorithms/strings/PalindromeTest.java
index c98ebc2a..0545cdb9 100644
--- a/src/test/java/com/thealgorithms/strings/PalindromeTest.java
+++ b/src/test/java/com/thealgorithms/strings/PalindromeTest.java
@@ -7,13 +7,20 @@ public class PalindromeTest {
 
     @Test
     public void palindrome() {
-        String input1 = "kayak";
-        String input2 = "kayaks";
-        Assertions.assertTrue(Palindrome.isPalindrome(input1));
-        Assertions.assertFalse(Palindrome.isPalindrome(input2));
-        Assertions.assertTrue(Palindrome.isPalindromeRecursion(input1));
-        Assertions.assertFalse(Palindrome.isPalindromeRecursion(input2));
-        Assertions.assertTrue(Palindrome.isPalindrome1(input1));
-        Assertions.assertFalse(Palindrome.isPalindrome1(input2));
+
+        String[] palindromes = { null, "", "aba", "123321", "kayak" };
+        for (String s : palindromes) {
+            Assertions.assertTrue(Palindrome.isPalindrome(s) &&
+            Palindrome.isPalindromeRecursion(s) &&
+            Palindrome.isPalindromeTwoPointer(s));
+        }
+
+        String[] notPalindromes = { "abb", "abc", "abc123", "kayaks" };
+        for (String s : notPalindromes) {
+            Assertions.assertFalse(Palindrome.isPalindrome(s) ||
+            Palindrome.isPalindromeRecursion(s) ||
+            Palindrome.isPalindromeTwoPointer(s));
+        }
+        
     }
 }