Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Copying ArrayList

Thread view: 
ruds - 06 Jun 2007 06:06 GMT
hi,
I have 2 arraylists al1 and al2. I'm copying al1 to al2 i.e.
al2=al1;
if i'm removing some elements from al2, the same elements from al1 too
are removed.
why so?
How do i prevent it?
How to copy array list can i clone it?
Abhishek  Srivastava - 06 Jun 2007 06:25 GMT
> hi,
> I have 2 arraylists al1 and al2. I'm copying al1 to al2 i.e.
[quoted text clipped - 4 lines]
> How do i prevent it?
> How to copy array list can i clone it?

http://java.sun.com/developer/JDCTechTips/2001/tt0410.html

- Abhi
ruds - 06 Jun 2007 07:26 GMT
Thanks a lot..
Roedy Green - 15 Jun 2007 11:20 GMT
>hi,
>I have 2 arraylists al1 and al2. I'm copying al1 to al2 i.e.
[quoted text clipped - 4 lines]
>How do i prevent it?
>How to copy array list can i clone it?

all copying with

arraylist2 = arraylist1

does in give you two pointers to the same ArrayList.

You need to clone the ArrayList.

See if clone is defined.  

See if there is a constructor that takes another ArrayList or List.

In a pinch, export an array and use that to create a new ArrayList.

see http://mindprod.com/jgloss/arraylist.html

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.