R
Razvan
Hi!
int [] arr = {21, 22, 23};
int [] arr = new int [] {21, 22, 23};
The second form will create an array with 3 elements then it will
copy the values of the innitialization list (21, 22, 23). The first
form just declares a reference to the array {21, 22, 23} - no
suplimentary memory is allocated and no copy operation takes place, so
the first form should be preffered. Is this true ? ... or the compiler
makes some optimizations, practically rendering the 2 forms equivalent
? I doubt that it will, since the new operator guarantees that new
memory will be allocated.
Regards,
Razvan
int [] arr = {21, 22, 23};
int [] arr = new int [] {21, 22, 23};
The second form will create an array with 3 elements then it will
copy the values of the innitialization list (21, 22, 23). The first
form just declares a reference to the array {21, 22, 23} - no
suplimentary memory is allocated and no copy operation takes place, so
the first form should be preffered. Is this true ? ... or the compiler
makes some optimizations, practically rendering the 2 forms equivalent
? I doubt that it will, since the new operator guarantees that new
memory will be allocated.
Regards,
Razvan