JAVA快速求取两个集合的交集 Vector-retainAll

		Vector v1 = new Vector();
		v1.add(1);
		v1.add("A");
		v1.add("B");
		v1.add(2);
		System.out.println(v1);//[1, A, B, 2]
		
		Vector v2 = new Vector();
		v2.add(1);
		v2.add("A");
		v2.add(3);
		System.out.println(v2);//[1, A, 3]
		
		v1.retainAll(v2);
		System.out.println(v1);//[1, A]

API:

retainAll

public boolean retainAll(Collection<?> c)
在此向量中仅保留包含在指定 Collection 中的元素。换句话说,从此向量中移除所有未包含在指定 Collection 中的元素。

指定者:
接口 Collection<E> 中的 retainAll
指定者:
接口 List<E> 中的 retainAll
覆盖:
AbstractCollection<E> 中的 retainAll
参数:
c - 要在此向量中保留的元素的 collection(移除其他所有元素)
返回:
如果此向量由于调用而更改,则返回 true
抛出:
ClassCastException - 如果此向量中的一个或多个元素的类型与指定 collection 不兼容(可选)
NullPointerException - 如果此向量包含一个或多个 null 元素并且指定 collection 不支持 null 元素(可选),或者指定 collection 为 null

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值