Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to clone Collections

Java: How to clone Collections
{filelink=11077}

import java.util.ArrayList;
import java.util.Iterator;
public class CloneCollection
{
  public static void main(String[] args)
  	{
    ArrayList list_tab = new ArrayList();
    for (int i = 0; i < 10; i++)
      list_tab.add(i);
    System.out.println("v: " + list_tab);
    // clone the ArrayList
    ArrayList list_tab2 = (ArrayList) list_tab.clone();
    // use cloned arrayList
    int x=0;
    for (Iterator e = list_tab2.iterator(); e.hasNext();)
    {
    	list_tab2.set(x,(Integer)e.next()*5);
    	x+=1;
    }
    System.out.println("v: " + list_tab2);
  }
}

Users who found this page were searching for:

  • java cloning collections
  • clone Collection java

No comments yet.

Leave a Comment