AF
Home
Tag
Submit Notes
Ask Anything
Login
Subscribe Us
A
ny
F
orum
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.
Follow @anyforumin
java-collection: How to copy the content of one ArrayList to another one?
I want to copy the content from one ArrayList to another one so that i can clear the first ArrayList to perform the further operations. Please give me the solution.
java x 211
collection x 52
Posted On :
2013-12-24 18:28:04.0
Garima Gupta
596
1295
60202
5
Answers
Yes you can easily do it by the following way :
1. Create the object of the ArrayList<String> by calling the constructor in which a list is passes as a parameter as following -
List<T> newList = new ArrayList<T>(oldList);
2. By cloning the object -
newList = (ArrayList<T>)oldList.clone();
and now you can clear the oldList for further use as follows :
oldList.clear();
Posted On :
2013-12-24 19:29:19
Satisfied :
1 Yes
0 No
Saksham Kumar
734
339
39909
Reply This Thread
5
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in