copy all elements from one list to another ajav 1

copy all elements from one list to another ajav

originalArrayList.addAll(copyArrayofList);

Here is what the above code is Doing:
1. We create an ArrayList of String type and add some elements to it.
2. We create a copy of the original ArrayList using the copy constructor.
3. We add some more elements to the original ArrayList.
4. We print the original ArrayList and the copy ArrayList.

Output:

Original ArrayList: [A, B, C, D, E]
Copy of ArrayList: [A, B, C, D, E]
Original ArrayList after copy: [A, B, C, D, E, F, G]
Copy of ArrayList after original is modified: [A, B, C, D, E]

Similar Posts