Powered by Blogger.

Copy Elements from one ArrayList to Another ArrayList

>> Sunday, October 17, 2010

Here is the Program to copy the values from one ArrayList to another ArrayList.

package collect;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


public class ListClas {
 public static void main(String[] args) {

  List l1=new ArrayList(); 
  
  l1.add("hi");
  l1.add("brother");
  
  ArrayList al=new ArrayList(); 
  al.add("hello");  
  al.add("guru");   
  
  Collections.copy(al,l1);   
  Iterator i= al.iterator();  
  
  while(i.hasNext()){ 
   i.hasNext();  
   System.out.print(" "+i.next()); 
   //System.out.println(al);  
  }   
 }  
}

This is the procedure to copying the objects from one list to another.

For Java References:
Effective Java (2nd Edition) 

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.