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

java 集合addall_Java集合的addAll()方法和示例相关推荐

  1. java集合示例_Java集合的addAll()方法和示例

    集合类addAll()方法addAll()方法在java.lang包中可用. addAll()方法用于将所有给定元素(ele)放入给定集合(co). addAll()方法是一个静态方法,可以使用类名进 ...

  2. 集合源码解读----addAll方法

    在多次写测试demo时,在初始化List时,总是很麻烦,需要多次调用add方法, List是提供 addAll(Collection<? extends E> c)方法的,其实现是将集合c ...

  3. java enummap_Java EnumMap size()方法与示例

    java enummap EnumMap类的size()方法 (EnumMap Class size() method) size() method is available in java.util ...

  4. java treemap_Java TreeMap size()方法与示例

    java treemap TreeMap类的size()方法 (TreeMap Class size() method) size() method is available in java.util ...

  5. java scanner_Java Scanner nextLong()方法与示例

    java scanner 扫描器类的nextLong()方法 (Scanner Class nextLong() method) Syntax: 句法: public long nextLong(); ...

  6. Java Math类toDegrees()方法与示例

    数学类toDegrees()方法 (Math class toDegrees() method) toDegrees() method is available in java.lang packag ...

  7. java timezone_Java TimeZone getDSTSavings()方法与示例

    java timezone TimeZone类的getDSTSavings()方法 (TimeZone Class getDSTSavings() method) getDSTSavings() me ...

  8. Java LinkedList void clear()方法与示例

    LinkedList void clear()方法 (LinkedList void clear() method) This method is available in package java. ...

  9. java enummap_Java EnumMap get()方法与示例

    java enummap EnumMap类的get()方法 (EnumMap Class get() method) get() method is available in java.util pa ...

最新文章

  1. 思科交换机各类型中字母的意思?
  2. 近4万Star,登月源码登顶GitHub,这位女程序员“拯救”了阿波罗
  3. 用进化算法来优化SVM的参数C和Gamma——利用SCOOP库进行分布式加速计算
  4. stm32c8t6的can通信实验代码_TCP的连接建立与关闭状态及数据传输通信过程【含有 PHP socket API 测试实验代码】...
  5. 解决研发管理问题的途径
  6. Android中shape中的属性大全
  7. JavaScript从入门到放弃 -(四)E5 新增方法
  8. 信息学奥赛一本通(1318:【例5.3】自然数的拆分)
  9. 【英语学习】【Daily English】U06 Shopping L03 What sort of market are you looking for?
  10. PyCharm中脚本文件无法识别相对路径
  11. widevine level1测试视频的生成方法
  12. STM32-GPIO的配置和使用
  13. 生信过程中的各种文件格式
  14. static关键字的用法
  15. Mysql 关闭3306端口设置远程访问
  16. 电气转行嵌入式还是java_19 届 985 毕业生想从电气行业转行到 IT 行业,你们怎么看?...
  17. 游戏性能优化指南:如何将HTML5性能发挥到极致
  18. Windows下cmd命令—systeminfo
  19. VisualVM 启动报错Error Starting VisualVM:You are running VisualVM using Java Runtime Environment(JRE)
  20. 技术博客一件发布系统的实验性技术方案Butterfly

热门文章

  1. (九)linux中断编程
  2. c语言宏定义比较三个数大小,C语言中两个宏进行大小对比,其中一个没有定义,这种行为如何定义。...
  3. 金蝶kis专业版公网访问_金蝶KIS云专业版—【账务处理】进阶操作101问
  4. 织梦php网站修改教程,织梦DEDEcms织梦软件模型增加图集功能教程(含修改文件下载)...
  5. pcb天线和纯铜天线_如何简化天线设计?相控阵波束成形IC来助您
  6. android studio 跨进程,Android IPC机制(三)在Android Studio中使用AIDL实现跨进程方法调用...
  7. atlas安装需要kafka吗_Atlas 2.1.0 实践(2)—— 安装Atlas
  8. Python 面向对象(中)
  9. Centos7: 配置IO调度
  10. springboot中使用缓存shiro-ehcache