java 集合addall_Java集合的addAll()方法和示例

java 集合addall

集合类的addAll()方法 (Collections Class addAll() method)

  • addAll() Method is available in java.lang package.

    addAll()方法在java.lang包中可用。

  • addAll() Method is used to put all the given elements(ele) to the given collection (co).

    addAll()方法用于将所有给定的element( ele )放入给定的集合( co )。

  • addAll() Method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    addAll()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

  • addAll() Method may throw an exception at the time of add the elements(ele) to the given Collection(co).

    在将elements( ele )添加到给定Collection( co )时, addAll()方法可能会引发异常。

    • UnsupportedOperationException: This exception may throw when collection unsupport add() method.UnsupportedOperationException :集合不支持add()方法时,可能引发此异常。
    • NullPointerException: This exception may throw when elements (ele) may have at least one null & the given collection unsupport null.
    • NullPointerException :当元素( ele )可能至少具有一个null且给定的集合不支持null时,可能引发此异常。
    • IllegalArgumentException: This exception may throw when the given element (ele) is not valid.
    • IllegalArgumentException :如果给定元素( ele )无效,则可能引发此异常。

Syntax:

句法:

    public static boolean addAll(Collection co, Type.. ele);

Parameter(s):

参数:

  • Collection co – represents the container of "Collection" type.

    集合co –表示“集合”类型的容器。

  • Type.. ele – represents the elements to add into given collection co.

    Type .. ele –表示要添加到给定集合co中的元素。

Return value:

返回值:

The return type of the method is Boolean, it returns true when the given set of elements(ele) to be added into collection successfully otherwise it returns false.

该方法的返回类型为Boolean ,如果要成功将给定的元素集(ele)添加到集合中,则返回true,否则返回false。

Example:

例:

// Java Program is to demonstrate the example
// of boolean addAll(Collection co, Type.. ele) of Collections class
import java.util.*;
public class AddAll {
public static void main(String args[]) {
// Create a linked list object     
List link_list = new LinkedList();
// By using add() method is to add the
// given elements in linked list
link_list.add(10);
link_list.add(20);
link_list.add(30);
link_list.add(40);
link_list.add(50);
//Display Linked List
System.out.println("link_list: " + link_list);
// By using addAll() method is to add all the
// elements in the given collection linked list
boolean status = Collections.addAll(link_list, 60, 70, 80, 90);
System.out.println();
System.out.println("Collections.addAll(link_list, 60,70,80,90) :");
// Display Linked List
System.out.println("link_list: " + link_list);
}
}

Output

输出量

link_list: [10, 20, 30, 40, 50]Collections.addAll(link_list, 60,70,80,90) :
link_list: [10, 20, 30, 40, 50, 60, 70, 80, 90]

翻译自: https://www.includehelp.com/java/collections-addall-method-with-example.aspx

java 集合addall

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541413.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

国家可持续发展议程创新示范区创建工作推进会在北京召开

2019独角兽企业重金招聘Python工程师标准>>> 为推进地方申报国家可持续发展议程创新示范区相关工作,根据国家可持续发展议程创新示范区创建工作的进展及需求,2017年4月23日—25日,科技部社会发展科技司、中国21世纪议程管理中心在…

java控制台打印图片_java——控制台输入打印图形

1. 打印直角三角形需求说明:从控制台输入直角三角形的高度(行数)。每行*的数目依次为1、3、5、7等。实现思路:外层循环控制行数,根据用户输入的行数得到外层循环条件分析每行打印的内容:每一行均打印*号,第i行的*号数为…

Java日历compareTo()方法与示例

日历类的compareTo()方法 (Calendar Class compareTo() method) compareTo() method is available in java.util package. compareTo()方法在java.util包中可用。 compareTo() method is used to compare two Calendar objects or in other words, we can say this method is u…

在struts2中配置自定义拦截器放行多个方法

源码: 自定义的拦截器类: //自定义拦截器类:LoginInterceptor ; package com.java.action.interceptor; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionInvocation;im…

java多态和泛型_Java面向对象(二) 接口、多态和泛型

一、接口二、多态多态是同一个行为具有多个不同表现形式或形态的能力。2.1 类型转换转换方式隐式 向上转型对于基本数据类型,存储容量低的可自动向存储容量高的类型转换对于引用变量,子类可被转换为超类,可被赋给所属类实现的接口的引用显式 …

Java ArrayList contains()方法及示例

ArrayList类contains()方法 (ArrayList Class contains() method) contains() method is available in java.util package. contains()方法在java.util包中可用。 contains() method is used to check whether this Arraylist contains the given object or not. contains()方法…

BlockingQueue详解

前言: 在新增的Concurrent包中,BlockingQueue很好的解决了多线程中,如何高效安全“传输”数据的问题。通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便利。本文详细介绍了BlockingQueue家庭中的所…

java isempty_Java ArrayDeque isEmpty()方法与示例

java isemptyArrayDeque类isEmpty()方法 (ArrayDeque Class isEmpty() method) isEmpty() Method is available in java.lang package. isEmpty()方法在java.lang包中可用。 isEmpty() Method is used to check whether this deque is "empty" or "non-empty&qu…

[QGLViewer]3D场景鼠标点击位置

重载鼠标事件: void AxMapControl::mousePressEvent(QMouseEvent* e) {switch(currentTool){case AX_DRAW_DIRECTION:{if (e->button() Qt::LeftButton) {QPoint screenPte->pos();qglviewer::Vec orig1, dir1;camera()->convertClickToLine(screenPt, or…

elispce导入java项目_emacs的java编程环境设置(jdee,lib,cedet,ecb

1:下载jdee,lib,ecb。(已安装cedet就不用再安了)2:解压缩放入load-path目录。然后load,require。(add-to-list load-path "~/.emacs.d/lisp/jdee-2.4.0.1/lisp")(add-to-list load-path "~/.emacs.d/lisp/elib-1.0")(add…

element 项目 示例_Java ArrayDeque element()方法与示例

element 项目 示例ArrayDeque类element()方法 (ArrayDeque Class element() method) element() Method is available in java.lang package. element()方法在java.lang包中可用。 element() Method is used to retrieve the first element of the deque but without removing t…

can收发器 rx_CANOpen系列教程03 _CAN收发器功能、原理及作用

1写在前面前面文章是从大方向介绍了CAN网络,让大家对CAN网络有一定的认识。本文将范围缩小,讲述整个CAN网络其中的一个CAN收发器。如下图标记出来的部分:本文结合众多初学者容易产生的疑问来讲述CAN收发器相关的知识点,大概有如下…

操作系统文件分配策略_操作系统中的文件分配方法

操作系统文件分配策略分配方法 (Allocation Method) The allocation method defines how the files are stored in the disk blocks. The direct access nature of the disks gives us the flexibility to implement the files. In many cases, different files or many files …

简述container与container-fluid的区别

在bootstrap中的布局容器一栏中,提供了container与container-fluid两种容器,其官方解释为: .container 类用于固定宽度并支持响应式布局的容器。 .container-fluid 类用于 100% 宽度,占据全部视口(viewport&#xff09…

centos php fpm 停止_如何关闭php-fpm进程?

因为你是编译的,可以在源码中复制php-fpm的init文件到系统中:cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm然后就可以使用以下命令启动、停止、重启和重新加载php-fpm了:service php-fpm startservice php-fpm restartservice php-fpm…

minus_Java Duration类| minus()方法与示例

minus持续时间类minus()方法 (Duration Class minus() method) Syntax: 句法: public Duration minus(Duration d);public Duration minus(long amt, TemporalUnit t_unit);minus() method is available in java.time package. minus()方法在java.time包中可用。 m…

Mongodb聚合函数

插入 测试数据 for(var j1;j<3;j){ for(var i1;i<3;i){ var person{Name:"jack"i,Age:i,Address:["henan","wuhan"],Course:[{Name:"shuxue",Score:i},{Name:"wuli",Score:i}]}db.DemoTest.Person.insert(pers…

php rename函数_php rename函数怎么用

PHP rename()函数用于重命名文件或目录&#xff0c;语法“rename(文件旧名称,新名称,句柄环境)”&#xff0c;使用用户指定的新名称更改文件或目录的旧名称&#xff0c;并且可以根据需要在目录之间移动&#xff1b;成功时返回True&#xff0c;失败时返回False。php rename()函数…

Java BigInteger类| xor()方法与示例

BigInteger类的xor()方法 (BigInteger Class xor() method) xor() method is available in java.math package. xor()方法在java.math包中可用。 xor() method is used to perform xor operation between this BigInteger and the given BigInteger and we all know when we pe…

Spring Data Redis实战之提供RedisTemplate

为什么80%的码农都做不了架构师&#xff1f;>>> 参考&#xff1a; http://www.cnblogs.com/edwinchen/p/3816938.html 本项目创建的是Maven项目 一、pom.xml引入dependencies <dependency><groupId>org.springframework.data</groupId><artif…