I am interested how LinkedList is searching data when I want to get it.
For example:
We have a LinkedList with 1000 elements in it. And I want to take element by index 950 so I write "list.get (950)
". Will java starts to look for that element from the beginning? Or it has a pointer to the last element too?
I have written small programm to test it. But it works incorrectly(showing bigest time for the first get, whatever it is.
long time;
time = System.nanoTime();
list.get(1);
time = System.nanoTime() - time;
System.out.println("For element at the beginning " + time);
time = System.nanoTime();
list.get(999);
time = System.nanoTime() - time;
System.out.println("For element at the end " + time);