
Programmers know that they have to make defensive copies when necessary.

I have seen many bugs due to the fact that these lists are not persistent. The only question is whether they are useful for some use cases or not.Īrray-based lists are very error-prone too. Whether programmers are able or not to make an educated decision about using linked lists is irrelevant. Thinking that programmers would be worst than I am or even as bad as I am and that it would be a valid reason to remove linked lists would be basing the decision upon cognitive bias. What I meant is that it was insulting for programmers in general, and that insult is not an argument. We add elements using the add() method that the LinkedList class inherits from the Collection interface.I certainly didn’t feel insulted. How to add elements to LinkedList in Java? LinkedList inherits the same methods as ArrayList, so we use exactly the same methods to manipulate elements. Or using polymorphism. The variable that holds the address of the new object will be of type List. This is possible because LinkedList implements the List interface. LinkedList list = new LinkedList() īetween the brackets, we specify which type of elements the list will contain.

We create a new LinkedList object by instantiating it, just like any other class in Java.

