Java Programing laungage

java.util Projects

java.util Project 1

Creating a Copy of Collection

In this programming tutorials we shall be learn how to create and then copy the collection. The copied collection contains the reference to the object. In-fact, objects are not cloned.

Previous Home Next

The following program creates a collection (list) and copy for the duplicate collection with content of that. The new copied collection has the reference of the source collection. When you use the copied collection for viewing contents of that then the copied collection referenced to the source collection and views it's elements.


package r4r;
import java.util.*;
public class copycollection {
public static void main(String[] args){
List<String> list1 = Arrays.asList(new String[]{"parisonz", ""});
System.out.println("Content of the original list : " + list1);
List copiedList = new ArrayList<String>(list1);
System.out.println("Content of the copied list : " + copiedList);

Previous Home Next