java.util.Vector.containsAll()方法用于检查向量是否包含向量中的所有元素是否指定集合。如果向量包含指定 Collection 中的所有元素,则返回 true,否则返回 false。
语法
public boolean containsAll(Collection<?> c)
参数
c | 指定将测试其元素是否包含在向量中的集合。 |
返回值
如果向量包含指定 Collection 中的所有元素,则返回 true,否则返回 false。
异常
抛出 NullPointerException ,如果指定的集合为 null。
示例:
在下面的示例中,java.util.Vector.containsAll() 方法用于检查向量MyVector是否包含名为MyList的LinkedList的所有元素。
import java.util.*;
public class MyClass {
public static void main(String[] args) {
//创建向量
Vector<Integer> MyVector = new Vector<Integer>();
//填充向量
MyVector.add(10);
MyVector.add(20);
MyVector.add(30);
MyVector.add(40);
//创建链表
LinkedList<Integer> MyList = new LinkedList<Integer>();
//填充链表
MyVector.add(20);
MyVector.add(40);
//检查遏制
if(MyVector.containsAll(MyList))
System.out.println("MyVector contains all elements of MyList.");
else
System.out.println("MyVector does not contain all elements of MyList.");
}
}
上述代码的输出将是:
MyVector contains all elements of MyList.