Declaring an array filled with Objects
class ArrayEx tries to create an array of java.lang.Object(s), but it won’t. All it will do is to create an array of 4 elements, but each of the element will contain null. Unlike declaring and initializing Java primitives where the array elements will be populated automatically with the default primitive values (int, short, boolean, float etc), array of type Objects or Reference types are not automatically populated.
class ArrayEx2 shows the code on how to declare and fill up arrays of types java.lang.Object(s)—it holds true also when declarating other arrays which are not primitive types.
If you want to show appreciation for my efforts dear reader, you could buy me a tall hazel nut Americano ($2) via PayPal. Thanks
Leave a comment