When I went through the implementation of ArrayList, I found a strange piece of code in the toArray (T []) method.
public <T> T[] toArray(T[] a) { if (a.length < size)
Part,
if (a.length > size) a[size] = null;
why is only the element at this index in the array null? After the array is filled with the contents of the list, the elements in the remaining indices should be set to zero, right? Or am I missing something here?
source share