从java中删除元素向量

从java中删除元素向量,java,vector,Java,Vector,我有两个向量,元素如下: vect 1 = [111111 5, 111111 5, 222222 5, 333333 5, 111111 2] vect 2 = [111111 5, 222222 4, 333333 2, 111111 2, 444444 8, 333333 5, 111111 1, 222222 5] 在Java中,如何删除向量2中存在的向量1的元素 我想得到这个结果: vect 2 = [222222 4, 333333 2, 444444 8, 111111 1]

我有两个向量,元素如下:

vect 1 = [111111 5, 111111 5, 222222 5, 333333 5, 111111 2]
vect 2 = [111111 5, 222222 4, 333333 2, 111111 2, 444444 8, 333333 5, 111111 1, 222222 5]
在Java中,如何删除向量2中存在的向量1的元素

我想得到这个结果:

vect 2 = [222222 4, 333333 2, 444444 8, 111111 1]

谢谢

使用
collToRemoveFrom.removeAll(集合)

使用
collToRemoveFrom.removeAll(集合)

您可以使用
Collection
removeAll(Collection c)
方法。这适用于任何
集合

因此,您可以执行以下操作:

List v1 = ....
List v2 = ....
v2.removeAll(v1); // Now v2 contains only elements of original v2 not present in v1

您可以使用
Collection
removeAll(Collection c)
方法。这适用于任何
集合

因此,您可以执行以下操作:

List v1 = ....
List v2 = ....
v2.removeAll(v1); // Now v2 contains only elements of original v2 not present in v1

尝试移除向量的所有方法

public static void main(String[] args) {
    Vector v1 = new Vector();
    Vector v2 = new Vector();

    v1.add(1111);
    v2.add(1111);
    v2.add(2222);

    v2.removeAll(v1);
    System.out.println(v2);

}

尝试移除向量的所有方法

public static void main(String[] args) {
    Vector v1 = new Vector();
    Vector v2 = new Vector();

    v1.add(1111);
    v2.add(1111);
    v2.add(2222);

    v2.removeAll(v1);
    System.out.println(v2);

}

请再加一点细节。你的向量是什么?数组,
Vector
s,
List
s?您好,抱歉。。它是一个类似于
Vector monVectorTemp=new Vector()的向量请添加更多详细信息。你的向量是什么?数组,
Vector
s,
List
s?您好,抱歉。。它是一个类似于
Vector monVectorTemp=new Vector()的向量