Consider the following two calls to the same method in java:-
1) doSomething(new Object[]{"something"}) ;
2)
Object[] obj = {"something"} ;
doSomething(obj);
Which one is more efficient in terms of memory and time efficiency ? I would say the 1) is better in both memory and time efficiency. Reason being in the second option requires us to create another variable (extra memory) and then assigns that value to the variable (extra time). Any comments ?
Just to clarify the object will be create only once, i am talking about the extra variable being used to hold the address of the newly created object.
obj
no matter what, it's a question of when/ifobj
will be garbage collected.