LinkedList boolean addAll(Collection extends E> c) method Example Program
By candid | Posted :
Jun 24, 2015
| Updated :
Jun 24, 2015
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
Program
package com.candidjava;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.addAll(Collection<? extends E> c)
* method appends all of the elements in the specified collection
* to the end of this list, in the order that they are returned by
* the specified collection's iterator.
*
*/
public class LinkedListAddAll {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("anandh");
list.add("hari");
list.add("vinoth");
list.add("kamal");
list.add("karthic");
System.out.println("LinkedList:" + list);
Collection collection = new ArrayList();
collection.add("mohan");
collection.add("siva");
collection.add("sankar");
list.addAll(collection);
System.out.println("LinkedList:" + list);
}
}
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractCollection<E>
Parameters:
c - collection containing elements to be added to this list
Returns:
true if this list changed as a result of the call
Throws:
NullPointerException - if the specified collection is null