Skip to content

Investigate insertion in the middle of ArrayList vs LinkedList

License

Notifications You must be signed in to change notification settings

rpanchyk/arraylist-vs-linkedlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Investigate insertion in the middle of ArrayList vs LinkedList.

Results

As shown below, insertion in ArrayList takes much less time instead of LinkedList.

Filling java.util.ArrayList with 1000000 elements ... done
Filling java.util.LinkedList with 1000000 elements ... done

Time elapsed for java.util.ArrayList: 3 ms
Time elapsed for java.util.LinkedList: 15 ms

Why?

The source code of java.util.ArrayList.add(int, E) method (Java 11):

ArrayList

The source code of java.util.LinkedList.add(int, E) method (Java 11):

LinkedList

Questions

Create new issue or pull request if any.

About

Investigate insertion in the middle of ArrayList vs LinkedList

Topics

Resources

License

Stars

Watchers

Forks

Languages