AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
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 ?.



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
profile Garima Gupta - anyforum.in Garima Gupta
596129558962
up-rate
5
down-rate

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
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939091
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in