If I have the following:
List<String> list = new ArrayList<>(Arrays.asList("a","b","c"));
and call:
System.out.println(list.size());
It will print 3 as expected.
The size()
method's code is just return size;
where size
is a private int
.
So I'm wondering where it's actually setting that size
variable.
I see it's calling the constructor public ArrayList(Collection<? extends E> c)
, which is fine, but when I debug into there, and hover over c
, it already says size = 3
.
So is it something in Collection<? extends E> c
that's setting it to 3, before it gets to the ArrayList
constructor?