LinkedList boolean addAll(Collection c) method Example Program


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);
	}
}

Output

LinkedList:[anandh, hari, vinoth, kamal, karthic]
LinkedList:[anandh, hari, vinoth, kamal, karthic, mohan, siva, sankar]

Explanation

public boolean addAll(Collection<? extends E> c)
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
See Also:
AbstractCollection.add(Object)


Related Post

Comments


©candidjava.com