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

歡迎訪問 生活随笔!

生活随笔

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

java

Java LinkedList boolean addAll(int index,Collection c)方法,带有示例

發布時間:2025/3/11 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java LinkedList boolean addAll(int index,Collection c)方法,带有示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LinkedList boolean addAll(int index,Collection c)方法 (LinkedList boolean addAll(int index, Collection c) method)

  • This method is available in package java.util.Collection and here, Collection is an interface.

    該方法在java.util.Collection包中可用,在這里, Collection是一個接口。

  • In this method, the index is the position where we have to start inserting the Collection elements and Collection is the list of elements whether Collection is of ArrayList, LinkedList type, etc.

    在此方法中,索引是我們必須開始插入Collection元素的位置,而Collection是元素列表,無論Collection是ArrayList,LinkedList類型還是其他類型。

  • This method is used to insert the collection of objects at the specified position in the linked list.

    此方法用于在鏈接列表的指定位置插入對象的集合。

  • Index position starts from 0.

    索引位置從0開始。

Syntax:

句法:

boolean addAll(int index , Collection c){}

Parameter(s):

參數:

We can pass two arguments as a parameter in the method and the Collection parameter is the collection of elements will add from the starting position of the specified index in the linked list.

我們可以在方法中傳遞兩個參數作為參數,而Collection參數是將從鏈表中指定索引的起始位置開始添加的元素集合。

Return value:

返回值:

The return type of this method is boolean that means this method returns true during execution of at least inserting of one element.

該方法的返回類型為布爾值 ,這意味著該方法在至少插入一個元素的過程中返回true。

Java程序演示LinkedList addAll(int index,Collection c)方法的示例 (Java program to demonstrate example of LinkedList addAll(int index, Collection c) method)

import java.util.LinkedList; import java.util.ArrayList;public class LinkList {public static void main(String args[]) {// Creating a LinkedList LinkedList list = new LinkedList();// Use add() method to add objects // in the LinkedListlist.add("J");list.add("A");list.add("V");list.add("A");// Creating a Collection ArrayList object // of ArrayList TypeArrayList al = new ArrayList();al.add("P");al.add("R");al.add("O");al.add("G");al.add("R");al.add("A");al.add("M");al.add("M");al.add("I");al.add("N");al.add("G");// Displaying the Current LinkedList System.out.println("The Current LinkedList is: " + list);// Appending the collection ArrayList to the // LinkedList and ArrayList will start inserting // from index 4(i.e. From Fifth Position )list.addAll(4, al);// Displaying the new LinkedListSystem.out.println("The new linked list is: " + list);} }

Output

輸出量

D:\Programs>javac LinkList.javaD:\Programs>java LinkList The Current LinkedList is: [J, A, V, A] The new linked list is: [J, A, V, A, P, R, O, G, R, A, M, M, I, N, G]

翻譯自: https://www.includehelp.com/java/linkedlist-boolean-addall-int-index-collection-c-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java LinkedList boolean addAll(int index,Collection c)方法,带有示例的全部內容,希望文章能夠幫你解決所遇到的問題。

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