import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CollectionsCopyMethodExample {
public static void main(String args[]){
List<String> dataList = new ArrayList<String>();
dataList.add("Ball");
dataList.add("Apple");
dataList.add("Dog");
dataList.add("Cat");
List<String> dataList2 = new ArrayList<String>();
dataList2.add("Eagle");
dataList2.add("Gun");
System.out.println("Before");
System.out.println(dataList);
System.out.println(dataList2);
//Copying dataList2 items to dataList
//Copying item from dataList2 to dataList index by index.
//If copying index is not in dataList then throws ArraysIndexOutOfBoundsException
Collections.copy(dataList, dataList2);
System.out.println("After");
System.out.println(dataList);
System.out.println(dataList2);
}
}