Knowledge Walls
John Peter
Pune, Maharashtra, India
Copy method to copy collections list in Java
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>();
        List<String> dataList2 = new ArrayList<String>();
        //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);
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details