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(Collection 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.

Here is the code

/**
 * @ # Add1.java
 * A class repersenting use to add(int index,E element) 
 * method of LinkedList class in java.util package
 * version 15 May 2008
 * author Rose India 
 */
import java.util.*;

public class Add1 {

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

        //Add the specified element to the end of this list.
        list.add(i);
        list.add(str);
        System.out.println("arrlist = " + list);
        
        //Add specified element at the specified position in this list.
         list.add(1,11);
         System.out.println("arrlist = " + list);
    }
}

Output
list = [0, Rose India]
list1 = [0, 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