11:38 am - Wednesday May 24, 2017

Add elements to LinkedList using boolean addall(E e)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This tutorial explains how  to Add elements to LinkedList using boolean addall() method.

Adds all of the elements in the specified collection to this collection.

The behavior of this operation is undefined if the specified collection is modified while

    the  operation is in progress.

Example

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.List;

public class  AddallElements

{

 public static void main(String a[])

 {         
       LinkedList<String> arr = new LinkedList<String>();      

       arr.add("First");

       arr.add("Second");

       arr.add("Third");

       arr.add("Random");

       System.out.println("Actual LinkedList:"+arr);

       List<String> list = new ArrayList<String>();

       list.add("one");

       list.add("two");

       arr.addAll(list);

       System.out.println("After Copy: "+arr);;

       list.addAll(arr);

       System.out.println(""+list);

   }

}

Output

        Actual LinkedList:[First, Second, Third, Random]

        After Copy: [First, Second, Third, Random, one, two]

        [one, two, First, Second, Third, Random, one, two]

BACK

Filed in: Java Examples

Comments are closed.