Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Array list deep copy

 
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

Array list deep copy

ArrayList clone() example
import java.util.ArrayList;
 
public class ArrayListExample 
{
    @SuppressWarnings("unchecked")
    public static void main(String[] args) 
    {
        ArrayList<String> arrayListObject = new ArrayList<>(); 
         
        arrayListObject.add("A");
        arrayListObject.add("B");
        arrayListObject.add("C");
        arrayListObject.add("D");
         
        System.out.println(arrayListObject);   
         
        ArrayList<String> arrayListClone =  (ArrayList<String>) arrayListObject.clone();
         
        System.out.println(arrayListClone);   
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: terminate a frame java 
Java :: android separator line in view 
Java :: isanagram java 
Java :: charat(0).touppercase() java 
Java :: set path in windows 
Java :: fill two dimensional array columns by columns java 
Java :: string to stream java 
Java :: java arraylist declaration 
Java :: java error message 
Java :: java regex 
Java :: how to get current date in java 
Java :: integer.tostring java 
Java :: how to get color from resource android 
Java :: how to run individual test in java maven 
Java :: Java NoClassDefFoundError but class is there 
Java :: boucles java 
Java :: java files 
Java :: how generate a random number in java between 3 and 5 
Java :: spring db properties 
Java :: dot operator java 
Java :: java get month 
Java :: hide icon android studio 
Java :: java input string with spaces 
Java :: quicksort for arraylist 
Java :: how to display the decimal value when 0 after point android studio 
Java :: if driver.find_element_by_xpath selnium java is displayed 
Java :: greater than sign in java 
Java :: how to multiply bigdecimals 
Java :: java enum 
Java :: input file in java 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =