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
Post a Comment