Repository: TheAlgorithms/Java
Pull request #4479 (2023-10-01 06:39:44)

Update Pangram.java using Java Collections
A simple separate function isPangramOrNot(String s) has been created which implements the Pangram checking of a string using Java Collection Framework approach.

<!-- 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] All filenames are in PascalCase.
- [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.


Ankit-Saha08: I request the maintainer(s) to merge my request using "hacktoberfest-accepted" label.
debasishbsws: Looks like you haven't add test for your function. (It is always better to add test you know)
https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/strings/PangramTest.java
Add some test for you method too. you can use the same example just with your method call.
and `isPangramUsingSet(String s)` is a better name 
Ankit-Saha08: Ok, I will update the method name isPangramUsingSet(String s) and also add some tests for my method.
Ankit-Saha08: Hi, I have updated the function name to isPangramUsingSet(String s) and also added tests for my function.

P.S. - I would be grateful if my contribution is accepted and merged using "hacktoberfest-accepted" label.
debasishbsws: Add the test in this barnch.
Ankit-Saha08: Hey, I am facing an issue while trying to commit the changes in PangramTest.java file. I am unable to find this PR branch while trying to commit the changes in the test file. What should I do now?

Like this current branch name is - "patch-4" but while trying to select the branch before committing it isn't showing up there. Looking forward for some gainful insight on resolving this
Ankit-Saha08: Hii, I have updated the test cases in PangramTest.java file in this current PR branch itself. 

**P.S. - Looking forward to having my contribution merged and accepted.**

Patch:
diff --git a/src/main/java/com/thealgorithms/strings/Pangram.java b/src/main/java/com/thealgorithms/strings/Pangram.java
index 4772ac82..9d734579 100644
--- a/src/main/java/com/thealgorithms/strings/Pangram.java
+++ b/src/main/java/com/thealgorithms/strings/Pangram.java
@@ -1,5 +1,7 @@
 package com.thealgorithms.strings;
 
+import java.util.HashSet;
+
 /**
  * Wikipedia: https://en.wikipedia.org/wiki/Pangram
  */
@@ -15,6 +17,22 @@ public class Pangram {
         assert !isPangram("\u0000/\\");
     }
 
+    /**
+     * Checks if a String is considered a Pangram
+     *
+     * @param s The String to check
+     * @return {@code true} if s is a Pangram, otherwise {@code false}
+     */
+    // alternative approach using Java Collection Framework
+    public static boolean isPangramUsingSet(String s) {
+        HashSet<Character> alpha = new HashSet<Character>();
+        s = s.trim().toLowerCase();
+        for (int i = 0; i < s.length(); i++)
+            if (s.charAt(i) != ' ') alpha.add(s.charAt(i));
+        if (alpha.size() == 26) return true;
+        return false;
+    }
+
     /**
      * Checks if a String is considered a Pangram
      *


Test patch:
diff --git a/src/test/java/com/thealgorithms/strings/PangramTest.java b/src/test/java/com/thealgorithms/strings/PangramTest.java
index 5d138a5e..7ad79b20 100644
--- a/src/test/java/com/thealgorithms/strings/PangramTest.java
+++ b/src/test/java/com/thealgorithms/strings/PangramTest.java
@@ -17,5 +17,10 @@ public class PangramTest {
         assertFalse(Pangram.isPangram2("The quick brown fox jumps over the azy dog")); // L is missing
         assertFalse(Pangram.isPangram2("+-1234 This string is not alphabetical"));
         assertFalse(Pangram.isPangram2("\u0000/\\ Invalid characters are alright too"));
+
+        assertTrue(Pangram.isPangramUsingSet("The quick brown fox jumps over the lazy dog"));
+        assertFalse(Pangram.isPangramUsingSet("The quick brown fox jumps over the azy dog")); // L is missing
+        assertFalse(Pangram.isPangramUsingSet("+-1234 This string is not alphabetical"));
+        assertFalse(Pangram.isPangramUsingSet("\u0000/\\ Invalid characters are alright too"));
     }
 }