Is it mandatory to instantiate a List (using Arraylist) in JAVA? -


is mandatory instantiate list using arraylist in java perform operations on it?

can this:

list<webelement> rows=htmltable.findelements(by.tagname("tr")); 

will work?

where not instantiating list :

list<webelement> rows = new arraylist<webelement>();  

and going getting values variable "rows" by:

rows = htmltable.findelements(by.tagname("tr")); 

what difference between 2 approaches mentioned above? if 1 more step of instantiating "rows" , getting values it?

to work actual object need, well, actual object, not null reference. how obtain object, eg. instantiating yourself, parameter or return value other method, doesn't matter.

list rows=htmltable.findelements(by.tagname("tr")); //will work?

if htmltable.findelements(by.tagname("tr")) returns list<webelement> object, yes, work.

"what difference between 2 approaches mentioned above?"

creating new instance will, well, create new independent instance (in case of arraylist: empty list object). if you're getting object method, it's responsibilty of method create or object. allows reuse objects in different methods passing object references. in case work webelement list object of htmltable. if makes sense in use case or if need work new, fresh instance, can tell. have consider if need manipulate list, if possible returned list (is unmodifiable?) , effect htmltable.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -