Given: this doesn't work for immutable objects like String
1. if you directly assign one ArrayList reference to another, modifying the common
list elements in any of the lists will be reflected in both of the lists.
2.
if arrayList1 is used to create arrayList2 using [Link](arrayList1),
modifying the common list elements using append, replace...(operated/performed on
individual elements) in any of the lists will be reflected in both of the lists.
But other modifications like add, remove, set,... (operated/performed on either of
the lists arrayList1 or arrayList2) will be reflected on the corresponding list.
eg:
import [Link];
import [Link];
import [Link];
import [Link];
public class IC2 {
public IC2(String s) {
}
public static void main(String[] args) {
ArrayList<StringBuilder> alb = new ArrayList<>();
StringBuilder aa = new StringBuilder("AA");
[Link](aa);
[Link](new StringBuilder("BB"));
ArrayList<StringBuilder> alb2 = new ArrayList<>();
[Link](alb);
// [Link]("[Link](0, new StringBuilder(\"SB\"))");
[Link](0, 1, "#"); //reflects both
// [Link](0, new StringBuilder("##"));//reflects this(alb2)
//[Link](0);
[Link](new StringBuilder("NEW"));
// for (StringBuilder val : alb2) {
// //[Link](val);
// //[Link](0, new StringBuilder("##"));
// [Link](1, 2, "$$");
//// [Link]("&&");
// }
[Link]("alb");
for (StringBuilder val : alb) {
[Link](val);
}
[Link]("alb2");
for (StringBuilder val : alb2) {
[Link](val);
}
}
}