I have some questions regarding arrays in java:
How many objects are created in the following expressions?
(a) new int[0] : There is one object created, an array of size 0.???
(b) new int[2][2] : There is one object created, an array with 2 rows and columns.???
(c) new int[2][] : There is no object created???
I was wondering if my solutions next to the expressions are correct. If not, hopefuly you can help and give me some explanation about them. I don’t really get what im supposed to do.
Thanks in advance!
new int[0]
Yes this is an empty array, one object is created.
new int[2][2]
Yes this creates and array with 2 rows and columns, 3 objects are created.
new int[2][]
Java supports jagged arrays. This means when you create
int[2][]this means you have an array of various sizedint[]. Only 1 object is created here.