Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java empty array list vs null elements

The difference is in the List size, not its capacity.
When instantiating a new ArrayList<>(5), the initial capacity is set to 5,
but the size remains 0, because we haven't added any elements.
If we invoke add(null) only the elements size() will increase
and all functions iterating through the array of elements
will remain inbetween the size of the List, not the capacity.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #empty #array #list #null #elements
ADD COMMENT
Topic
Name
5+5 =