I'm having an issue understanding the output of size() for a "nested" ArrayList:
ArrayList<ArrayList<ArrayList<ArrayList<String>>>> myEmpls = new ArrayList<>();
ArrayList<ArrayList<ArrayList<String>>> dummy2 = new ArrayList<>();
ArrayList<ArrayList<String>> dummy = new ArrayList<>();
for (int x = 0; x < 4; x++) {
myEmpls.add(dummy2);
}
System.out.println(myEmpls.size());
// returns 4 as expected
System.out.println(myEmpls.get(0).size());
System.out.println(myEmpls.get(1).size());
// both return 0 as expected
for (int x = 0; x < 10; x++) {
myEmpls.get(0).add(dummy);
}
System.out.println(myEmpls.get(1).size());
// returns 10 altough I added to myEmpls.get(0) and not
// myEmpls.get(1) so I expected this to still be 0.
Can someone explain why this is the case? Maybe I am missing something obvious.
Thanks in advance.