Wednesday 15 May 2013

java - In what sense can a LinkedList be said to not support random access? -


indicates that there is no "random access" in the linked list, can anyone explain this to me?

given

  linked list & lt; String & gt; L = new linked list & lt; & Gt; ();   

Then I can use,

  l.get (n);   

Given this, why is the article "no random access"?

Random access here means that you can add any elements directly to the link list Can not use. In the linked list, you have to start by traverse each element (link) from head and then you can reach that element.

  l.get (n);   

This method works in the same way in the background. It passes through the head and then receives nth element

No comments:

Post a Comment