I have an ArrayList
l1
of size 10. I assign l1
to new list reference type l2
. Will l1
and l2
po
Yes l1
and l2
will point to the same reference, same object.
If you want to create a new ArrayList based on the other ArrayList you do this:
List l1 = new ArrayList();
l1.add("Hello");
l1.add("World");
List l2 = new ArrayList(l1); //A new arrayList.
l2.add("Everybody");
The result will be l1
will still have 2 elements and l2
will have 3 elements.