I just recently learned cloning in Java. There is deep cloning and shallow cloning. I was wandering what does the ArrayList does when objects added to it. Does it clon?
I made some tests with String object.
String s = new String("hello");
ArrayList<String> list = new ArrayList<String>();
list.add(s);
s = s.replace('h','y');
System.out.prinln(list.get(0));
It printed out "hello". So it does clon. Then I remembered from personal experience, when I add objects I wrote to an array, it doesn't clon. When I change the one in the array, original changes too.
I searched google, not sure because my lack of searching skills, I didn't find the answer I was looking for. Then I searched StackOverFlow, again nothing I was looking for.
So what is the deal with ArrayList? I am sorry if this question is duplicate, I really searched.
Some people didn't understand the question: Does ArrayList clon? (which is the main question I am looking the answer of) If not so why String did get cloned?