diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java
index 09574ab51..82ff58263 100644
--- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java
+++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java
@@ -274,14 +274,9 @@ public class Utils {
/**
* Concatenate all non-null, non-empty and strings which are not equal to "null"
.
*/
- public static String nonEmptyAndNullJoin(final String delimiter, final String[] elements) {
- final List list = Arrays.asList(elements);
- for (int i = list.size() - 1; i >= 0; i--) {
- if (isNullOrEmpty(list.get(i)) || list.get(i).equals("null")) {
- list.remove(i);
- }
- }
-
+ public static String nonEmptyAndNullJoin(final CharSequence delimiter, final String[] elements) {
+ final List list = new java.util.ArrayList<>(Arrays.asList(elements));
+ list.removeIf(s -> isNullOrEmpty(s) || s.equals("null"));
return join(delimiter, list);
}
}
diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/utils/UtilsTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/utils/UtilsTest.java
index e4a65505b..a81270de0 100644
--- a/extractor/src/test/java/org/schabi/newpipe/extractor/utils/UtilsTest.java
+++ b/extractor/src/test/java/org/schabi/newpipe/extractor/utils/UtilsTest.java
@@ -20,6 +20,7 @@ public class UtilsTest {
@Test
public void testJoin() {
assertEquals("some,random,stuff", Utils.join(",", Arrays.asList("some", "random", "stuff")));
+ assertEquals("some,random,not-null,stuff", Utils.nonEmptyAndNullJoin(",", new String[]{"some", "null", "random", "", "not-null", null, "stuff"}));
}
@Test