java - ArrayList declaration and handling -
i use arraylist in java software , insist program has clean possible.
i have ambiguity in arraylist variable declaration , usage.
so, is, among these 3 arraylist usages, correct way have choose?
case 1:
list<object> l = some_function();
case 2:
list<object> l = new arraylist<object>(); l = some_function(); //staff l.clear()
case 3:
list<object> l = null; l = some_function(); //staff l.clear()
function:
list<object> some_function(){ list<object> list = new ayyarlist<object>(); //staff return list; }
my question function is: java clear list variable automatically, or have clean using clear()
api , how then? }
in opinion, case 1 better. 2nd case create unnecessary arraylist
object, lost when assign method return value.
does java clear list variable automatically, or have clean using clean() api , how then?
java won't clear list, have clear it, check api, arraylist#clear()
how can clear list manually if declared inside function , should use later outside function(its outputs)
you have assign returned list temporary list, can clear list.
list<object> returnedlist = some_function(); //stuff returnedlist.clear()
list<object> some_function() { list<object> list = new ayyarlist<object>(); //stuff return list; }
Comments
Post a Comment