Copying all of the elements

Copying all of the elements from one list into another. After the operation, the index of each copied
element in the destination list will be identical to its index in the source list. The destination list must be at least as long as the source list. If it is longer, the remaining elements in the destination list are unaffected.
 package collection.demos;

import java.util.ArrayList;
import java.util.Collections;

public class CopyingElementsList {

    public static void main(String[] args) {
        ArrayList<String> activities = new ArrayList<String>();
        ArrayList<String> projects = new ArrayList<String>() {{ add("Database");add("OS");add("Office");}};
        System.out.println("List of activities : " + activities);
        System.out.println("List of projects   : " + projects);
        Collections.copy(activities, projects);
        System.out.println("List activities    : " + activities);


No comments:

Popular Posts