org.testng.collections.Lists Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testng Show documentation
Show all versions of testng Show documentation
Testing framework for Java
package org.testng.collections;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
public final class Lists {
private Lists() {}
public static List newArrayList() {
return new ArrayList<>();
}
public static List newLinkedList() {
return new LinkedList<>();
}
public static List newLinkedList(Collection c) {
return new LinkedList<>(c);
}
public static List newArrayList(Collection c) {
return new ArrayList<>(c);
}
@SafeVarargs
public static List newArrayList(K... elements) {
List result = new ArrayList<>();
Collections.addAll(result, elements);
return result;
}
public static List newArrayList(int size) {
return new ArrayList<>(size);
}
public static List intersection(List list1, List list2) {
return list1.stream().filter(list2::contains).collect(Collectors.toList());
}
public static List merge(Collection l1, Collection l2) {
List result = newArrayList(l1);
result.addAll(l2);
return result;
}
}