AbstractSequentialList的addAll(int index,Collection C)方法用於將作為參數傳遞給此函數的集合中的所有元素附加到此函數的抽象順序列表的特定索引或位置。
用法:
boolean addAll(int index, Collection C)
參數:此函數接受上麵語法中所示的兩個參數,並在下麵進行描述。
- index:此參數為整數數據類型,並指定列表中從容器元素插入位置開始的位置。
- C:這是一個集合,其元素需要附加。
返回值:如果至少執行了一個附加動作,則該方法返回TRUE。
以下示例程序旨在說明Java.util.AbstractSequentialList.addAll()方法:
範例1:
// Java code to illustrate addAll() method
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
// Creating an empty AbstractSequentialList
AbstractSequentialList<String>
absqlist = new LinkedList<String>();
// Use add() method to add elements
absqlist.add("Geeks");
absqlist.add("for");
absqlist.add("Geeks");
absqlist.add("10");
absqlist.add("20");
// Creating a Collection
Collection<String>
collect = new ArrayList<String>();
collect.add("A");
collect.add("Computer");
collect.add("Portal");
collect.add("for");
collect.add("Geeks");
// Displaying the list
System.out.println("AbstractSequentialList:"
+ absqlist);
// Appending the collection to the list
absqlist.addAll(1, collect);
// Clearing the list using clear() and displaying
System.out.println("The new list is:"
+ absqlist);
}
}
輸出:
AbstractSequentialList:[Geeks, for, Geeks, 10, 20] The new list is:[Geeks, A, Computer, Portal, for, Geeks, for, Geeks, 10, 20]
範例2:
// Java code to illustrate boolean addAll()
import java.util.*;
import java.util.AbstractSequentialList;
public class AbstractSequentialListDemo {
public static void main(String args[])
{
// Creating an empty AbstractSequentialList
AbstractSequentialList<Integer>
absqlist = new LinkedList<Integer>();
// Use add() method to add elements
absqlist.add(10);
absqlist.add(20);
absqlist.add(30);
absqlist.add(10);
absqlist.add(20);
// Creating a Collection
Collection<Integer>
collect = new LinkedList<Integer>();
collect.add(1);
collect.add(2);
collect.add(3);
collect.add(4);
collect.add(5);
// Displaying the list
System.out.println("The AbstractSequentialList is:"
+ absqlist);
// Appending the collection to the list
absqlist.addAll(1, collect);
// Clearing the list using clear() and displaying
System.out.println("The new list is:" + absqlist);
}
}
輸出:
The AbstractSequentialList is:[10, 20, 30, 10, 20] The new list is:[10, 1, 2, 3, 4, 5, 20, 30, 10, 20]
相關用法
- Java AbstractSequentialList get()用法及代碼示例
- Java AbstractSequentialList set()用法及代碼示例
- Java Set addAll()用法及代碼示例
- Java AbstractSequentialList remove()用法及代碼示例
- Java CopyOnWriteArraySet addAll()用法及代碼示例
- Java ConcurrentLinkedDeque addAll()用法及代碼示例
- Java LinkedBlockingDeque addAll()用法及代碼示例
- Java List addAll()用法及代碼示例
- Java Collection addAll()用法及代碼示例
- Java Collections addAll()用法及代碼示例
- Java SortedSet addAll()用法及代碼示例
- Java AbstractQueue addAll()用法及代碼示例
- Java CopyOnWriteArrayList addAll()用法及代碼示例
- Java AbstractCollection addAll()用法及代碼示例
- Java AbstractList addAll()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 AbstractSequentialList addAll() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。