Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java arraylist deepcopy

 
public class CloneArrayListMain {
 
    public static void main(String[] args) {
        ArrayList<Student> studentList = new ArrayList<>();
        studentList.add(new Student("Rohan","102",new Date(2002, 02, 12)));
        studentList.add(new Student("David","105",new Date(1999, 05, 30)));
 
        ArrayList<Student> clonedStudentList = new ArrayList<>();
 
        for(Student st:studentList)
        {
            clonedStudentList.add(st.clone());
        }
        // Update list
        clonedStudentList.get(0).setName("John");
        System.out.println("-----------Original List-----------");
        studentList.forEach(e->System.out.println(e.getName()+" "+e.getId()));
        System.out.println("-----------Copied List----------");
        clonedStudentList.forEach(e->System.out.println(e.getName()+" "+e.getId()));
    }
}
 
Comment

PREVIOUS NEXT
Code Example
Java :: java get number out of string 
Java :: isnull java 
Java :: convert javascritp getTime() to datetime 
Java :: reverse int array java 
Java :: arrays.aslist 
Java :: java create empty arraylist 
Java :: android application class 
Java :: write an infinite loop java 
Java :: javafx start 
Java :: findviewbyid in kotlin Just using id name . 
Java :: create a list java 
Java :: spring maven plugin 
Java :: how to find the size of a queue in java 
Java :: jdbc interface 
Java :: parse object to int java 
Java :: java long to double 
Java :: difference between object and class 
Java :: generating random number 
Java :: java swing menu click event 
Java :: Converting String Array to an Integer Array 
Java :: java using .indexof to fin a space 
Java :: final finally finalize 
Java :: code to include layout from java in android 
Java :: java what is at 
Java :: HUFFMAN CODING IN JAVA 
Java :: android dialog box example 
Java :: pre increment and post increments java 
Java :: java android development find element by id 
Java :: java add element to existing array 
Java :: socket in java 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =