I think you are confused about what you think of ArrayList as ArrayList objects, not ArrayList object references.
ArrayList of Object represents a list of object references available for the index.
Indeed, for such a reference, do not refer to the real object, but instead to "null".
Therefore, you have five reference slots, each with a null value.
This is not the same as a series of four zeros or zero zeros.
Look at your initial and primitive array of strings - its length is five, not zero.
Or even easier, when you have a class with a field of type Object, it still takes a space, regardless of whether it refers to something or not. Otherwise, you will not be able to instantiate the class and not redistribute it when you really assigned something to the field.
source share