Repository: TheAlgorithms/Java
Pull request #6078 (2024-11-01 11:25:30)

General performance improvement:
1- Replaced single element lists with java's singletonList to conserve memory. 
2- Replaced empty lists with java's emptyList() to conserve memory. 
3- Removed commented code.
4- Fixed classes without set package.
5- Replaced string concatenations with StringBuilders'. 
6- Other minor improvements.

<!--
Thank you for your contribution!
In order to reduce the number of notifications sent to the maintainers, please:
- create your PR as draft, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests,
- make sure that all of the CI checks pass,
- mark your PR as ready for review, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review
-->

<!-- 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.
- [x] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) Report
Attention: Patch coverage is `61.76471%` with `13 lines` in your changes missing coverage. Please review.
> Project coverage is 73.45%. Comparing base [(`7b962a4`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/7b962a4a1d7611d0712743362b542cf3082cfb16?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) to head [(`0e89e57`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/0e89e570629ad072636ea390c86af1049b0e6060?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

| [Files with missing lines](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) | Patch % | Lines |
|---|---|---|
| [...om/thealgorithms/conversions/AnyBaseToAnyBase.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fconversions%2FAnyBaseToAnyBase.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9jb252ZXJzaW9ucy9BbnlCYXNlVG9BbnlCYXNlLmphdmE=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |
| [...thealgorithms/conversions/HexaDecimalToBinary.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fconversions%2FHexaDecimalToBinary.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9jb252ZXJzaW9ucy9IZXhhRGVjaW1hbFRvQmluYXJ5LmphdmE=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |
| [.../java/com/thealgorithms/ciphers/ProductCipher.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fciphers%2FProductCipher.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9jaXBoZXJzL1Byb2R1Y3RDaXBoZXIuamF2YQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |
| [...orithms/datastructures/lists/SinglyLinkedList.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fdatastructures%2Flists%2FSinglyLinkedList.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9kYXRhc3RydWN0dXJlcy9saXN0cy9TaW5nbHlMaW5rZWRMaXN0LmphdmE=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |
| [...in/java/com/thealgorithms/maths/VampireNumber.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fmaths%2FVampireNumber.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9tYXRocy9WYW1waXJlTnVtYmVyLmphdmE=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |
| [...ain/java/com/thealgorithms/sorts/LinkListSort.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fsorts%2FLinkListSort.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9zb3J0cy9MaW5rTGlzdFNvcnQuamF2YQ==) | 0.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff              @@
##             master    #6078      +/-   ##
============================================
+ Coverage     73.44%   73.45%   +0.01%     
- Complexity     5082     5096      +14     
============================================
  Files           657      657              
  Lines         17632    17631       -1     
  Branches       3396     3394       -2     
============================================
+ Hits          12949    12951       +2     
+ Misses         4181     4176       -5     
- Partials        502      504       +2     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6078?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).


Patch:
diff --git a/src/main/java/com/thealgorithms/ciphers/AES.java b/src/main/java/com/thealgorithms/ciphers/AES.java
index 5d614afb..1c283f6b 100644
--- a/src/main/java/com/thealgorithms/ciphers/AES.java
+++ b/src/main/java/com/thealgorithms/ciphers/AES.java
@@ -2418,8 +2418,6 @@ public final class AES {
             rBytes = new StringBuilder(rBytes.substring(0, i * 2) + currentByteBits + rBytes.substring((i + 1) * 2));
         }
 
-        // t = new BigInteger(rBytes, 16);
-        // return t;
         return new BigInteger(rBytes.toString(), 16);
     }
 
diff --git a/src/main/java/com/thealgorithms/ciphers/AffineCipher.java b/src/main/java/com/thealgorithms/ciphers/AffineCipher.java
index 636323b6..b8268137 100644
--- a/src/main/java/com/thealgorithms/ciphers/AffineCipher.java
+++ b/src/main/java/com/thealgorithms/ciphers/AffineCipher.java
@@ -34,19 +34,19 @@ final class AffineCipher {
      */
     static String encryptMessage(char[] msg) {
         // Cipher Text initially empty
-        String cipher = "";
+        StringBuilder cipher = new StringBuilder();
         for (int i = 0; i < msg.length; i++) {
             // Avoid space to be encrypted
             /* applying encryption formula ( a * x + b ) mod m
             {here x is msg[i] and m is 26} and added 'A' to
             bring it in the range of ASCII alphabet [65-90 | A-Z] */
             if (msg[i] != ' ') {
-                cipher += (char) ((((a * (msg[i] - 'A')) + b) % 26) + 'A');
+                cipher.append((char) ((((a * (msg[i] - 'A')) + b) % 26) + 'A'));
             } else { // else simply append space character
-                cipher += msg[i];
+                cipher.append(msg[i]);
             }
         }
-        return cipher;
+        return cipher.toString();
     }
 
     /**
@@ -56,7 +56,7 @@ final class AffineCipher {
      * @return the decrypted plaintext message
      */
     static String decryptCipher(String cipher) {
-        String msg = "";
+        StringBuilder msg = new StringBuilder();
         int aInv = 0;
         int flag;
 
@@ -75,13 +75,13 @@ final class AffineCipher {
             {here x is cipher[i] and m is 26} and added 'A'
             to bring it in the range of ASCII alphabet [65-90 | A-Z] */
             if (cipher.charAt(i) != ' ') {
-                msg += (char) (((aInv * ((cipher.charAt(i) - 'A') - b + 26)) % 26) + 'A');
+                msg.append((char) (((aInv * ((cipher.charAt(i) - 'A') - b + 26)) % 26) + 'A'));
             } else { // else simply append space character
-                msg += cipher.charAt(i);
+                msg.append(cipher.charAt(i));
             }
         }
 
-        return msg;
+        return msg.toString();
     }
 
     // Driver code
diff --git a/src/main/java/com/thealgorithms/ciphers/Blowfish.java b/src/main/java/com/thealgorithms/ciphers/Blowfish.java
index f6a0a375..ea1807e6 100644
--- a/src/main/java/com/thealgorithms/ciphers/Blowfish.java
+++ b/src/main/java/com/thealgorithms/ciphers/Blowfish.java
@@ -1078,7 +1078,7 @@ public class Blowfish {
      * @return String object which is a binary representation of the hex number passed as parameter
      */
     private String hexToBin(String hex) {
-        String binary = "";
+        StringBuilder binary = new StringBuilder();
         long num;
         String binary4B;
         int n = hex.length();
@@ -1089,9 +1089,9 @@ public class Blowfish {
             binary4B = "0000" + binary4B;
 
             binary4B = binary4B.substring(binary4B.length() - 4);
-            binary += binary4B;
+            binary.append(binary4B);
         }
-        return binary;
+        return binary.toString();
     }
 
     /**
@@ -1103,12 +1103,12 @@ public class Blowfish {
      */
     private String binToHex(String binary) {
         long num = Long.parseUnsignedLong(binary, 2);
-        String hex = Long.toHexString(num);
+        StringBuilder hex = new StringBuilder(Long.toHexString(num));
         while (hex.length() < (binary.length() / 4)) {
-            hex = "0" + hex;
+            hex.insert(0, "0");
         }
 
-        return hex;
+        return hex.toString();
     }
 
     /**
@@ -1121,12 +1121,12 @@ public class Blowfish {
     private String xor(String a, String b) {
         a = hexToBin(a);
         b = hexToBin(b);
-        String ans = "";
+        StringBuilder ans = new StringBuilder();
         for (int i = 0; i < a.length(); i++) {
-            ans += (char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0');
+            ans.append((char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0'));
         }
-        ans = binToHex(ans);
-        return ans;
+        ans = new StringBuilder(binToHex(ans.toString()));
+        return ans.toString();
     }
 
     /**
diff --git a/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java b/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java
index 4bd9c74a..7a9448fd 100644
--- a/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java
+++ b/src/main/java/com/thealgorithms/conversions/AnyBaseToAnyBase.java
@@ -136,7 +136,7 @@ public final class AnyBaseToAnyBase {
         int decimalValue = 0;
         int charB2;
         char charB1;
-        String output = "";
+        StringBuilder output = new StringBuilder();
         // Go through every character of n
         for (int i = 0; i < n.length(); i++) {
             // store the character in charB1
@@ -167,15 +167,15 @@ public final class AnyBaseToAnyBase {
             // If the remainder is a digit < 10, simply add it to
             // the left side of the new number.
             if (decimalValue % b2 < 10) {
-                output = decimalValue % b2 + output;
+                output.insert(0, decimalValue % b2);
             } // If the remainder is >= 10, add a character with the
             // corresponding value to the new number. (A = 10, B = 11, C = 12, ...)
             else {
-                output = (char) ((decimalValue % b2) + 55) + output;
+                output.insert(0, (char) ((decimalValue % b2) + 55));
             }
             // Divide by the new base again
             decimalValue /= b2;
         }
-        return output;
+        return output.toString();
     }
 }
diff --git a/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java b/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java
index 07acefc9..c0eb9a01 100644
--- a/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java
+++ b/src/main/java/com/thealgorithms/conversions/HexaDecimalToBinary.java
@@ -52,9 +52,11 @@ public class HexaDecimalToBinary {
      */
     public String completeDigits(String binNum) {
         final int byteSize = 8;
-        while (binNum.length() < byteSize) {
-            binNum = "0" + binNum;
+        StringBuilder binNumBuilder = new StringBuilder(binNum);
+        while (binNumBuilder.length() < byteSize) {
+            binNumBuilder.insert(0, "0");
         }
+        binNum = binNumBuilder.toString();
         return binNum;
     }
 }
diff --git a/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java b/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java
index 66dc6782..e5e673a2 100644
--- a/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java
+++ b/src/main/java/com/thealgorithms/datastructures/graphs/FloydWarshall.java
@@ -42,9 +42,7 @@ public class FloydWarshall {
     public void floydwarshall(int[][] adjacencyMatrix) {
         // Initialize the distance matrix with the adjacency matrix.
         for (int source = 1; source <= numberofvertices; source++) {
-            for (int destination = 1; destination <= numberofvertices; destination++) {
-                distanceMatrix[source][destination] = adjacencyMatrix[source][destination];
-            }
+            System.arraycopy(adjacencyMatrix[source], 1, distanceMatrix[source], 1, numberofvertices);
         }
         for (int intermediate = 1; intermediate <= numberofvertices; intermediate++) {
             for (int source = 1; source <= numberofvertices; source++) {
diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
index d5d3f31f..eb6cdf48 100644
--- a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
+++ b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
@@ -403,7 +403,7 @@ public class SinglyLinkedList implements Iterable<Integer> {
         SinglyLinkedList list = new SinglyLinkedList();
         assert list.isEmpty();
         assert list.size() == 0 && list.count() == 0;
-        assert list.toString().equals("");
+        assert list.toString().isEmpty();
 
         /* Test insert function */
         list.insertHead(5);
diff --git a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java
index a2e36f33..7d969a59 100644
--- a/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java
+++ b/src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java
@@ -23,6 +23,7 @@ public class GenericTree {
     }
 
     private final Node root;
+
     public GenericTree() { // Constructor
         Scanner scn = new Scanner(System.in);
         root = createTreeG(null, 0, scn);
@@ -225,8 +226,6 @@ public class GenericTree {
         for (int i = 0; i < node.child.size(); i++) {
             if (node.child.get(i).child.size() == 0) {
                 arr.add(i);
-                // node.child.remove(i);
-                // i--;
             } else {
                 removeleaves(node.child.get(i));
             }
diff --git a/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java b/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
index 87d4e89d..ba75b2f4 100644
--- a/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
+++ b/src/main/java/com/thealgorithms/graph/StronglyConnectedComponentOptimized.java
@@ -1,3 +1,5 @@
+package com.thealgorithms.graph;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
diff --git a/src/main/java/com/thealgorithms/maths/NthUglyNumber.java b/src/main/java/com/thealgorithms/maths/NthUglyNumber.java
index 6484026c..2da22c4c 100644
--- a/src/main/java/com/thealgorithms/maths/NthUglyNumber.java
+++ b/src/main/java/com/thealgorithms/maths/NthUglyNumber.java
@@ -1,7 +1,8 @@
 package com.thealgorithms.maths;
 
+import static java.util.Collections.singletonList;
+
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Map;
 import org.apache.commons.lang3.tuple.MutablePair;
 
@@ -16,7 +17,7 @@ import org.apache.commons.lang3.tuple.MutablePair;
  *     - the base [2, 3, 5] ugly numbers are the same as base [5, 6, 2, 3, 5] ugly numbers
  */
 public class NthUglyNumber {
-    private ArrayList<Long> uglyNumbers = new ArrayList<>(Arrays.asList(1L));
+    private ArrayList<Long> uglyNumbers = new ArrayList<>(singletonList(1L));
     private ArrayList<MutablePair<Integer, Integer>> positions = new ArrayList<>();
 
     /**
diff --git a/src/main/java/com/thealgorithms/maths/VampireNumber.java b/src/main/java/com/thealgorithms/maths/VampireNumber.java
index d64c82c6..8820f8a2 100644
--- a/src/main/java/com/thealgorithms/maths/VampireNumber.java
+++ b/src/main/java/com/thealgorithms/maths/VampireNumber.java
@@ -33,8 +33,7 @@ public final class VampireNumber {
                 // System.out.println(i+ " "+ j);
                 if (isVampireNumber(i, j, true)) {
                     countofRes++;
-                    res.append("" + countofRes + ": = ( " + i + "," + j + " = " + i * j + ")"
-                        + "\n");
+                    res.append("").append(countofRes).append(": = ( ").append(i).append(",").append(j).append(" = ").append(i * j).append(")").append("\n");
                 }
             }
         }
diff --git a/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java b/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java
index 1d8e2c51..414de4b2 100644
--- a/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java
+++ b/src/main/java/com/thealgorithms/scheduling/NonPreemptivePriorityScheduling.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.scheduling;
 
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.PriorityQueue;
 import java.util.Queue;
@@ -72,9 +73,7 @@ public final class NonPreemptivePriorityScheduling {
         int index = 0;
         Process[] executionOrder = new Process[processes.length];
 
-        for (Process process : processes) {
-            waitingQueue.add(process);
-        }
+        Collections.addAll(waitingQueue, processes);
 
         while (!waitingQueue.isEmpty() || !pq.isEmpty()) {
             // Add processes that have arrived to the priority queue


Test patch:
diff --git a/src/test/java/com/thealgorithms/backtracking/NQueensTest.java b/src/test/java/com/thealgorithms/backtracking/NQueensTest.java
index 977e3dfa..24313384 100644
--- a/src/test/java/com/thealgorithms/backtracking/NQueensTest.java
+++ b/src/test/java/com/thealgorithms/backtracking/NQueensTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.backtracking;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.ArrayList;
@@ -11,7 +12,7 @@ public class NQueensTest {
 
     @Test
     public void testNQueens1() {
-        List<List<String>> expected = Arrays.asList(Arrays.asList("Q"));
+        List<List<String>> expected = singletonList(singletonList("Q"));
         assertEquals(expected, NQueens.getNQueensArrangements(1));
     }
 
diff --git a/src/test/java/com/thealgorithms/bitmanipulation/GenerateSubsetsTest.java b/src/test/java/com/thealgorithms/bitmanipulation/GenerateSubsetsTest.java
index e3205d1d..912d7e72 100644
--- a/src/test/java/com/thealgorithms/bitmanipulation/GenerateSubsetsTest.java
+++ b/src/test/java/com/thealgorithms/bitmanipulation/GenerateSubsetsTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.bitmanipulation;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.ArrayList;
@@ -14,8 +15,8 @@ class GenerateSubsetsTest {
         int[] set = {1, 2};
         List<List<Integer>> expected = new ArrayList<>();
         expected.add(new ArrayList<>());
-        expected.add(Arrays.asList(1));
-        expected.add(Arrays.asList(2));
+        expected.add(singletonList(1));
+        expected.add(singletonList(2));
         expected.add(Arrays.asList(1, 2));
 
         List<List<Integer>> result = GenerateSubsets.generateSubsets(set);
@@ -27,7 +28,7 @@ class GenerateSubsetsTest {
         int[] set = {3};
         List<List<Integer>> expected = new ArrayList<>();
         expected.add(new ArrayList<>());
-        expected.add(Arrays.asList(3));
+        expected.add(singletonList(3));
 
         List<List<Integer>> result = GenerateSubsets.generateSubsets(set);
         assertEquals(expected, result);
@@ -38,10 +39,10 @@ class GenerateSubsetsTest {
         int[] set = {4, 5, 6};
         List<List<Integer>> expected = new ArrayList<>();
         expected.add(new ArrayList<>());
-        expected.add(Arrays.asList(4));
-        expected.add(Arrays.asList(5));
+        expected.add(singletonList(4));
+        expected.add(singletonList(5));
         expected.add(Arrays.asList(4, 5));
-        expected.add(Arrays.asList(6));
+        expected.add(singletonList(6));
         expected.add(Arrays.asList(4, 6));
         expected.add(Arrays.asList(5, 6));
         expected.add(Arrays.asList(4, 5, 6));
diff --git a/src/test/java/com/thealgorithms/datastructures/graphs/AStarTest.java b/src/test/java/com/thealgorithms/datastructures/graphs/AStarTest.java
index dce5a6ed..81077355 100644
--- a/src/test/java/com/thealgorithms/datastructures/graphs/AStarTest.java
+++ b/src/test/java/com/thealgorithms/datastructures/graphs/AStarTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.datastructures.graphs;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
@@ -41,6 +42,6 @@ public class AStarTest {
     public void testAStarSameNode() {
         AStar.PathAndDistance result = AStar.aStar(0, 0, graph, heuristic);
         assertEquals(0, result.getDistance(), "Expected distance from 0 to 0 is 0");
-        assertEquals(Arrays.asList(0), result.getPath(), "Expected path should only contain the start node");
+        assertEquals(singletonList(0), result.getPath(), "Expected path should only contain the start node");
     }
 }
diff --git a/src/test/java/com/thealgorithms/dynamicprogramming/AllConstructTest.java b/src/test/java/com/thealgorithms/dynamicprogramming/AllConstructTest.java
index 4979327f..01287692 100644
--- a/src/test/java/com/thealgorithms/dynamicprogramming/AllConstructTest.java
+++ b/src/test/java/com/thealgorithms/dynamicprogramming/AllConstructTest.java
@@ -1,5 +1,7 @@
 package com.thealgorithms.dynamicprogramming;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -10,7 +12,7 @@ public class AllConstructTest {
 
     @Test
     public void testAllConstructBasic() {
-        List<List<String>> expected = Arrays.asList(Arrays.asList("he", "l", "l", "o"));
+        List<List<String>> expected = singletonList(Arrays.asList("he", "l", "l", "o"));
         List<List<String>> result = AllConstruct.allConstruct("hello", Arrays.asList("he", "l", "o"));
         assertEquals(expected, result);
     }
@@ -24,14 +26,14 @@ public class AllConstructTest {
 
     @Test
     public void testAllConstructNoWays() {
-        List<List<String>> expected = Arrays.asList();
+        List<List<String>> expected = emptyList();
         List<List<String>> result = AllConstruct.allConstruct("abcdef", Arrays.asList("gh", "ijk"));
         assertEquals(expected, result);
     }
 
     @Test
     public void testAllConstructEmptyTarget() {
-        List<List<String>> expected = Arrays.asList(Arrays.asList());
+        List<List<String>> expected = singletonList(emptyList());
         List<List<String>> result = AllConstruct.allConstruct("", Arrays.asList("a", "b", "c"));
         assertEquals(expected, result);
     }
diff --git a/src/test/java/com/thealgorithms/dynamicprogramming/AssignmentUsingBitmaskTest.java b/src/test/java/com/thealgorithms/dynamicprogramming/AssignmentUsingBitmaskTest.java
index 0258f395..eadc43ce 100644
--- a/src/test/java/com/thealgorithms/dynamicprogramming/AssignmentUsingBitmaskTest.java
+++ b/src/test/java/com/thealgorithms/dynamicprogramming/AssignmentUsingBitmaskTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.dynamicprogramming;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -23,7 +24,7 @@ public final class AssignmentUsingBitmaskTest {
     public void testNoPossibleAssignments() {
         int totalTasks = 3;
 
-        List<List<Integer>> taskPerformed = Arrays.asList(Arrays.asList(2), Arrays.asList(3));
+        List<List<Integer>> taskPerformed = Arrays.asList(singletonList(2), singletonList(3));
 
         AssignmentUsingBitmask assignment = new AssignmentUsingBitmask(taskPerformed, totalTasks);
         int ways = assignment.countNoOfWays();
@@ -34,7 +35,7 @@ public final class AssignmentUsingBitmaskTest {
     public void testSinglePersonMultipleTasks() {
         int totalTasks = 3;
 
-        List<List<Integer>> taskPerformed = Arrays.asList(Arrays.asList(1, 2, 3));
+        List<List<Integer>> taskPerformed = singletonList(Arrays.asList(1, 2, 3));
 
         AssignmentUsingBitmask assignment = new AssignmentUsingBitmask(taskPerformed, totalTasks);
         int ways = assignment.countNoOfWays();
@@ -45,7 +46,7 @@ public final class AssignmentUsingBitmaskTest {
     public void testMultiplePeopleSingleTask() {
         int totalTasks = 1;
 
-        List<List<Integer>> taskPerformed = Arrays.asList(Arrays.asList(1), Arrays.asList(1));
+        List<List<Integer>> taskPerformed = Arrays.asList(singletonList(1), singletonList(1));
 
         AssignmentUsingBitmask assignment = new AssignmentUsingBitmask(taskPerformed, totalTasks);
         int ways = assignment.countNoOfWays();
diff --git a/src/test/java/com/thealgorithms/graph/StronglyConnectedComponentOptimizedTest.java b/src/test/java/com/thealgorithms/graph/StronglyConnectedComponentOptimizedTest.java
index 6f1c8a9d..9473a328 100644
--- a/src/test/java/com/thealgorithms/graph/StronglyConnectedComponentOptimizedTest.java
+++ b/src/test/java/com/thealgorithms/graph/StronglyConnectedComponentOptimizedTest.java
@@ -1,3 +1,5 @@
+package com.thealgorithms.graph;
+
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.ArrayList;
diff --git a/src/test/java/com/thealgorithms/greedyalgorithms/ActivitySelectionTest.java b/src/test/java/com/thealgorithms/greedyalgorithms/ActivitySelectionTest.java
index a997c198..d24264a3 100644
--- a/src/test/java/com/thealgorithms/greedyalgorithms/ActivitySelectionTest.java
+++ b/src/test/java/com/thealgorithms/greedyalgorithms/ActivitySelectionTest.java
@@ -1,9 +1,11 @@
 package com.thealgorithms.greedyalgorithms;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import org.junit.jupiter.api.Test;
 
 public class ActivitySelectionTest {
@@ -24,7 +26,7 @@ public class ActivitySelectionTest {
         int[] end = {2};
 
         ArrayList<Integer> result = ActivitySelection.activitySelection(start, end);
-        ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(0));
+        List<Integer> expected = singletonList(0);
 
         assertEquals(expected, result);
     }
diff --git a/src/test/java/com/thealgorithms/greedyalgorithms/CoinChangeTest.java b/src/test/java/com/thealgorithms/greedyalgorithms/CoinChangeTest.java
index e9d26771..b9745be6 100644
--- a/src/test/java/com/thealgorithms/greedyalgorithms/CoinChangeTest.java
+++ b/src/test/java/com/thealgorithms/greedyalgorithms/CoinChangeTest.java
@@ -1,9 +1,11 @@
 package com.thealgorithms.greedyalgorithms;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 import org.junit.jupiter.api.Test;
 
 public class CoinChangeTest {
@@ -16,7 +18,7 @@ public class CoinChangeTest {
 
     @Test
     public void testCoinChangeProblemWithLargeAmount() {
-        ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(2000));
+        List<Integer> expected = singletonList(2000);
         ArrayList<Integer> coins = CoinChange.coinChangeProblem(2000);
         assertEquals(expected, coins);
     }
diff --git a/src/test/java/com/thealgorithms/maths/ChineseRemainderTheoremTest.java b/src/test/java/com/thealgorithms/maths/ChineseRemainderTheoremTest.java
index 31c676d6..7c153ae4 100644
--- a/src/test/java/com/thealgorithms/maths/ChineseRemainderTheoremTest.java
+++ b/src/test/java/com/thealgorithms/maths/ChineseRemainderTheoremTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.maths;
 
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -27,8 +28,8 @@ public class ChineseRemainderTheoremTest {
 
     @Test
     public void testCRTWithSingleCongruence() {
-        List<Integer> remainders = Arrays.asList(4);
-        List<Integer> moduli = Arrays.asList(7);
+        List<Integer> remainders = singletonList(4);
+        List<Integer> moduli = singletonList(7);
         int expected = 4;
         int result = ChineseRemainderTheorem.solveCRT(remainders, moduli);
         assertEquals(expected, result);
diff --git a/src/test/java/com/thealgorithms/maths/MeansTest.java b/src/test/java/com/thealgorithms/maths/MeansTest.java
index bb2b4b6d..4b3a5df4 100644
--- a/src/test/java/com/thealgorithms/maths/MeansTest.java
+++ b/src/test/java/com/thealgorithms/maths/MeansTest.java
@@ -59,8 +59,7 @@ class MeansTest {
 
     @Test
     void geometricMeanMultipleNumbers() {
-        LinkedList<Double> numbers = new LinkedList<>();
-        numbers.addAll(Lists.newArrayList(1d, 2d, 3d, 4d, 5d, 6d, 1.25));
+        LinkedList<Double> numbers = new LinkedList<>(Lists.newArrayList(1d, 2d, 3d, 4d, 5d, 6d, 1.25));
         assertEquals(2.6426195539300585, Means.geometric(numbers));
     }
 
diff --git a/src/test/java/com/thealgorithms/misc/MedianOfMatrixtest.java b/src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java
similarity index 96%
rename from src/test/java/com/thealgorithms/misc/MedianOfMatrixtest.java
rename to src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java
index ec3a84b8..19bc6685 100644
--- a/src/test/java/com/thealgorithms/misc/MedianOfMatrixtest.java
+++ b/src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java
@@ -7,7 +7,7 @@ import java.util.Arrays;
 import java.util.List;
 import org.junit.jupiter.api.Test;
 
-public class MedianOfMatrixtest {
+public class MedianOfMatrixTest {
 
     @Test
     public void testMedianWithOddNumberOfElements() {
diff --git a/src/test/java/com/thealgorithms/others/FloydTriangleTest.java b/src/test/java/com/thealgorithms/others/FloydTriangleTest.java
index afa280c0..b336ac4b 100644
--- a/src/test/java/com/thealgorithms/others/FloydTriangleTest.java
+++ b/src/test/java/com/thealgorithms/others/FloydTriangleTest.java
@@ -1,5 +1,7 @@
 package com.thealgorithms.others;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -10,37 +12,37 @@ public class FloydTriangleTest {
 
     @Test
     public void testGenerateFloydTriangleWithValidInput() {
-        List<List<Integer>> expectedOutput = Arrays.asList(Arrays.asList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6));
+        List<List<Integer>> expectedOutput = Arrays.asList(singletonList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6));
         assertEquals(expectedOutput, FloydTriangle.generateFloydTriangle(3));
     }
 
     @Test
     public void testGenerateFloydTriangleWithOneRow() {
-        List<List<Integer>> expectedOutput = Arrays.asList(Arrays.asList(1));
+        List<List<Integer>> expectedOutput = singletonList(singletonList(1));
         assertEquals(expectedOutput, FloydTriangle.generateFloydTriangle(1));
     }
 
     @Test
     public void testGenerateFloydTriangleWithZeroRows() {
-        List<List<Integer>> expectedOutput = Arrays.asList();
+        List<List<Integer>> expectedOutput = emptyList();
         assertEquals(expectedOutput, FloydTriangle.generateFloydTriangle(0));
     }
 
     @Test
     public void testGenerateFloydTriangleWithNegativeRows() {
-        List<List<Integer>> expectedOutput = Arrays.asList();
+        List<List<Integer>> expectedOutput = emptyList();
         assertEquals(expectedOutput, FloydTriangle.generateFloydTriangle(-3));
     }
 
     @Test
     public void testGenerateFloydTriangleWithMultipleRows() {
-        List<List<Integer>> expectedOutput = Arrays.asList(Arrays.asList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9, 10), Arrays.asList(11, 12, 13, 14, 15));
+        List<List<Integer>> expectedOutput = Arrays.asList(singletonList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9, 10), Arrays.asList(11, 12, 13, 14, 15));
         assertEquals(expectedOutput, FloydTriangle.generateFloydTriangle(5));
     }
 
     @Test
     public void testGenerateFloydTriangleWithMoreMultipleRows() {
-        List<List<Integer>> expectedOutput = Arrays.asList(Arrays.asList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9, 10), Arrays.asList(11, 12, 13, 14, 15), Arrays.asList(16, 17, 18, 19, 20, 21), Arrays.asList(22, 23, 24, 25, 26, 27, 28));
+        List<List<Integer>> expectedOutput = Arrays.asList(singletonList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6), Arrays.asList(7, 8, 9, 10), Arrays.asList(11, 12, 13, 14, 15), Arrays.asList(16, 17, 18, 19, 20, 21), Arrays.asList(22, 23, 24, 25, 26, 27, 28));
         assertEquals(expectedOutput, FloydTriangle.generateFloydTriangle(7));
     }
 }
diff --git a/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularLookSchedulingTest.java b/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularLookSchedulingTest.java
index ae04e725..55429e41 100644
--- a/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularLookSchedulingTest.java
+++ b/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularLookSchedulingTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.scheduling.diskscheduling;
 
+import static java.util.Collections.emptyList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -31,8 +32,8 @@ public class CircularLookSchedulingTest {
     @Test
     public void testCircularLookSchedulingEmptyRequests() {
         CircularLookScheduling scheduling = new CircularLookScheduling(50, true, 200);
-        List<Integer> requests = Arrays.asList();
-        List<Integer> expected = Arrays.asList();
+        List<Integer> requests = emptyList();
+        List<Integer> expected = emptyList();
 
         List<Integer> result = scheduling.execute(requests);
         assertEquals(expected, result);
diff --git a/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularScanSchedulingTest.java b/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularScanSchedulingTest.java
index 06bd53c0..38daf510 100644
--- a/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularScanSchedulingTest.java
+++ b/src/test/java/com/thealgorithms/scheduling/diskscheduling/CircularScanSchedulingTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.scheduling.diskscheduling;
 
+import static java.util.Collections.emptyList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -39,8 +40,8 @@ public class CircularScanSchedulingTest {
     @Test
     public void testCircularScanSchedulingEmptyRequests() {
         CircularScanScheduling circularScan = new CircularScanScheduling(50, true, 200);
-        List<Integer> requests = Arrays.asList();
-        List<Integer> expectedOrder = Arrays.asList();
+        List<Integer> requests = emptyList();
+        List<Integer> expectedOrder = emptyList();
 
         List<Integer> result = circularScan.execute(requests);
         assertEquals(expectedOrder, result);
diff --git a/src/test/java/com/thealgorithms/scheduling/diskscheduling/LookSchedulingTest.java b/src/test/java/com/thealgorithms/scheduling/diskscheduling/LookSchedulingTest.java
index 91acc483..43ef1a69 100644
--- a/src/test/java/com/thealgorithms/scheduling/diskscheduling/LookSchedulingTest.java
+++ b/src/test/java/com/thealgorithms/scheduling/diskscheduling/LookSchedulingTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.scheduling.diskscheduling;
 
+import static java.util.Collections.emptyList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -31,8 +32,8 @@ public class LookSchedulingTest {
     @Test
     public void testLookSchedulingEmptyRequests() {
         LookScheduling lookScheduling = new LookScheduling(50, true, 200);
-        List<Integer> requests = Arrays.asList();
-        List<Integer> expected = Arrays.asList();
+        List<Integer> requests = emptyList();
+        List<Integer> expected = emptyList();
 
         List<Integer> result = lookScheduling.execute(requests);
         assertEquals(expected, result);
diff --git a/src/test/java/com/thealgorithms/scheduling/diskscheduling/ScanSchedulingTest.java b/src/test/java/com/thealgorithms/scheduling/diskscheduling/ScanSchedulingTest.java
index 1dbcd489..d1525d9a 100644
--- a/src/test/java/com/thealgorithms/scheduling/diskscheduling/ScanSchedulingTest.java
+++ b/src/test/java/com/thealgorithms/scheduling/diskscheduling/ScanSchedulingTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.scheduling.diskscheduling;
 
+import static java.util.Collections.emptyList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -31,8 +32,8 @@ public class ScanSchedulingTest {
     @Test
     public void testScanSchedulingEmptyRequests() {
         ScanScheduling scanScheduling = new ScanScheduling(50, true, 200);
-        List<Integer> requests = Arrays.asList();
-        List<Integer> expected = Arrays.asList();
+        List<Integer> requests = emptyList();
+        List<Integer> expected = emptyList();
 
         List<Integer> result = scanScheduling.execute(requests);
         assertEquals(expected, result);
diff --git a/src/test/java/com/thealgorithms/strings/WordLadderTest.java b/src/test/java/com/thealgorithms/strings/WordLadderTest.java
index 0854ad2b..22195341 100644
--- a/src/test/java/com/thealgorithms/strings/WordLadderTest.java
+++ b/src/test/java/com/thealgorithms/strings/WordLadderTest.java
@@ -1,5 +1,6 @@
 package com.thealgorithms.strings;
 
+import static java.util.Collections.emptyList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Arrays;
@@ -52,7 +53,7 @@ public class WordLadderTest {
     @Test
     public void testWordLadder3() {
 
-        List<String> wordList3 = Arrays.asList();
+        List<String> wordList3 = emptyList();
         assertEquals(WordLadder.ladderLength("hit", "cog", wordList3), 0);
     }