Related Examples
 

Java LinkedList addAll Example

LinkedList class addAll method example. This example shows you how to use addAll method.


LinkedList class addAll method example.public boolean addAll(int index, Collection c) Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.

Here is the code

/**
 * @ # AddAll1.java
 * A class repersenting use to addAll(int index,collection c) 
 * method of LinkedList class in java.util package
 * version 15 May 2008
 * author Rose India 
 */
import java.util.*;

public class AddAll1 {

    public static void main(String args[]) {
        List list = new LinkedList();
        List list1 = new LinkedList();
        int i = 0;
        String str = "Rose India";

        //Add the specified element to the end of this list.
        list.add(i);
        list.add(str);
        System.out.println("list = " + list);

        //Add the specified element to the end of this list.
        list1.add("Rose");
        list1.add("India");
        System.out.println("list1 = " + list1);

        //Insert all of the elements in the specified collection into the LinkedList  
        list.addAll(1,list1);
        System.out.println("list = " + list);
    }
}

Output
list = [0, Rose India]
list1 = [Rose, India]
list = [0, Rose India, Rose, India]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US