日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

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

發布時間:2025/3/11 java 60 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 classimport 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 listlink_list.add(10);link_list.add(20);link_list.add(30);link_list.add(40);link_list.add(50);//Display Linked ListSystem.out.println("link_list: " + link_list);// By using addAll() method is to add all the// elements in the given collection linked listboolean 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 ListSystem.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()方法和示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。