博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java Vector removeAll()方法与示例
阅读量:2536 次
发布时间:2019-05-11

本文共 2246 字,大约阅读时间需要 7 分钟。

向量类removeAll()方法 (Vector Class removeAll() method)

  • removeAll() method is available in java.util package.

    removeAll()方法在java.util包中可用。

  • removeAll() method is used to remove all of the existing elements in the given collection of this Vector.

    removeAll()方法用于删除此Vector的给定集合中的所有现有元素。

  • removeAll() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    removeAll()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • removeAll() method may throw an exception at the time of removing existing elements.

    removeAll()方法在删除现有元素时可能会引发异常。

    NullPointerException: This exception may throw when the given parameter is null exists.

    NullPointerException :当给定参数为null时,可能引发此异常。

Syntax:

句法:

public boolean removeAll(Collection co);

Parameter(s):

参数:

  • Collection co – represents the Collection object that contain elements to be removed from this Vector.

    Collection co –表示Collection对象,其中包含要从此Vector中删除的元素。

Return value:

返回值:

The return type of the method is boolean, it returns true when all elements of this Vector is to be removed that exists in the given collection otherwise it returns false.

方法的返回类型为boolean ,当要移除此Vector中存在于给定集合中的所有元素时,它返回true ,否则返回false

Example:

例:

// Java program to demonstrate the example // of boolean removeAll(Collection co)// method of Vector import java.util.*;public class RemoveAllOfVector {
public static void main(String[] args) {
// Instantiates a Vector object with // initial capacity of "10" Vector < String > v = new Vector < String > (10); ArrayList arr_l = new ArrayList(); // By using add() method is to add the // elements in this v v.add("C"); v.add("C++"); v.add("JAVA"); // By using add() method is to add the // elements in this arr_l arr_l.add("C"); arr_l.add("C++"); arr_l.add("SFDC"); // Display Vector and ArrayList System.out.println("v: " + v); System.out.println("arr_l: " + arr_l); // By using removeAll(arr_l) method is to // remove all elements of this vector v that // exists in the given collection arr_l v.removeAll(arr_l); // Display updated Vector System.out.println("v.removeAll(arr_l): " + v); }}

Output

输出量

v: [C, C++, JAVA]arr_l: [C, C++, SFDC]v.removeAll(arr_l): [JAVA]

翻译自:

转载地址:http://qzozd.baihongyu.com/

你可能感兴趣的文章
C_数据结构_链表
查看>>
kettle-连接控件
查看>>
Coursera--Neural Networks and Deep Learning Week 2
查看>>
C#中的委托和事件(续)【来自张子扬】
查看>>
机器学习部分国内牛人
查看>>
模拟Sping MVC
查看>>
Luogu 3261 [JLOI2015]城池攻占
查看>>
java修饰符
查看>>
C# Using 用法
查看>>
javascript函数的几种写法集合
查看>>
BZOJ第1页养成计划
查看>>
漫漫修行路
查看>>
js与jQuery的区别——每日一记录
查看>>
MyBatis 处理sql中的 大于,小于,大于等于,小于等于
查看>>
Lunix文件的读写权限问题
查看>>
Liferay 7:portlet name
查看>>
PostgreSQL9.6.3的REDIS测试
查看>>
解决pycharm问题:module 'pip' has no attribute 'main'
查看>>
002 lambda表达式
查看>>
springboot添加自定义注解
查看>>