Re: Strange things with java...



On May 11, 10:51 pm, Roberto Nicastro <robnicas...@xxxxxxxxx> wrote:
Hi all,
i have this piece of code

Suppose that lstA is List of 3 Objects

List<Object> lstA = ...something;
List<Object> lstB = lstA;
...
[block A] //this is a block of code
...

Inside block A i remove one item from lstA, so lstA become a List of 2
Objects. Inside block A i never touch lstB.
Why at the end of block A also lstB is with 2 elements? How is this
possible?

Thanks in advance

R

Actually here you have got one list in memory and 2 references to
that. So when u modify the list, it is reflected in either of
references pointing to that List.
HTH.

.