Choosing between ArrayList and LinkedList - JEP Cafe #20

How you can choose between ArrayList and LinkedList for your application: the full tutorial. The Collections Framework offers two implementation for the List interface: ArrayList and LinkedList. How can you choose the best one for your application? This JEP Café shows you how you can bench each implementation, and the amount of memory they consume. ⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯ 0:00 Intro 0:57 Choosing the best implementation for your use case 1:53 Choosing the most common operations for benchmark 2:43 Can you apply the O(n) complexity to your use case? 5:00 Using JMH to run your benchmarks 6:25 Reading elements from the beginning and the end of a list 9:03 Reading elements from the middle of a list 11:01 Introducing pointer chasing 12:51 Benching the impact of pointer chasing on LinkedList 14:27 Iterating over a list with an index or an Iterator 16:48 Creating an array-based list to speed up your iterations 17:53 Wrapping up pointer chasing 18:20 ArrayList caveats: insertion, deletion, and resizing 20:01 Benching insertion and resizing for ArrayList 21:48 Comparing inserting and adding for ArrayList and LinkedList 23:25 Comparing the memory consumption of ArrayList and LinkedList 26:27 Reducing your memory footprint by using trimToSize() 28:08 Wrapping up performances and memory consumption 30:26 Outro ⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯ ◦ JMH on GitHub, with doc and samples ➱ ◦ Alexey Shipilev’s blog ➱ ◦ Alexey Shipilev on JMH ➱ ◦ Java Object Layout on GitHub, with doc and samples ➱ ◦ Don Raab on Java Object Layout ➱ ◦ ➱ ◦ ➱ ◦ JDK 21 ➱ ◦ OpenJDK ➱ ◦ Oracle Java ➱ Tags: #Java #Java21 #OpenJDK #JDK #JDK21 #Collection #JEPCafe #insidejava
Back to Top