Java Collection (LinkedList Concepts) -


when declare linkedlist like:

list<string> names = new linkedlist<string>(); 

it not support of linkedlist's special methods (ex: names.peeklast(), names.pollfirst() )

but when declare like:

linkedlist<string> names = new linkedlist<string>(); 

then supports these methods.

yes, obvious reason reference, linkedlist contains that's methods , list not have!

but question when want work linkedlist, 1 better , correct? or usage of them?

if need use linkedlist methods don't exist in list, should use linkedlist reference (you use list reference , cast linkedlist in order call linkedlist specific methods, make less sense).

otherwise, preferable use list interface holding reference, since makes code more generic, since won't depend on specific list implementation.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -