What is index in linked List of java because linked list is not a continuous memory ???
List l=new linkedList();
l.get(index);
l.add(index);
- what is index in linkedList of java because linked list is not allocate continuous memory
What is index in linked List of java because linked list is not a continuous memory ???
List l=new linkedList();
l.get(index);
l.add(index);
If you are referring to java.util.LinkedList
, the index is simply the position of an element in the List
. Any List
implementation is an ordered Collection
, so elements can be accessed via their index.
However, for LinkedList
, methods such as get(index)
are not efficient, since they have to traverse the List
from its beginning or from its end (depending on which is closer to the required index), which takes linear time.