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
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