I have a LinkedList with 100000 items of String.When i do an operation with index such as get,remove,add, it seems same mechanism. First it browse the list to access Node[index], then does a another manipulation, with "get" it only references to item of Node, whereas even the "remove" does more. But why is the "get" operation take alot more time than the "remove" operation
for(int index=99999;index>=0;index--){
links.get(index);
}
get time in nanoseconds: 15083052805
for(int index=99999;index>=0;index--){
links.remove(index);
}
del time in nanoseconds: 2310625
LinkedList's functions:
public E get(int index) {
checkElementIndex(index);
return node(index).item;
}
public E remove(int index) {
checkElementIndex(index);
return unlink(node(index));
}