LinkedList vs ArrayList in Java Tutorial - Which Should You Use?

  Рет қаралды 570,181

Coding with John

Coding with John

3 жыл бұрын

Complete Java course: codingwithjohn.thinkific.com/...
Updated answer: Although the complexity analysis in this video still stands, in real world applications, ArrayList is the better choice for virtually every single use case. See the pinned comment below for more info.
LinkedLists are a great data structure to be familiar with, but they can be confusing. If you're familiar with ArrayLists in Java and how to use them, then LinkedLists can be used in the same way.
But when should you use a LinkedList vs. an ArrayList? How do you use them - are there any differences. We'll go over all of that and more in this beginner/intermediate Java video tutorial lesson.
Learn or improve your Java by watching it being coded live!
Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
Let me know what else you'd like to see!
Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
📕 THE best book to learn Java, Effective Java by Joshua Bloch
amzn.to/36AfdUu
📕 One of my favorite programming books, Clean Code by Robert Martin
amzn.to/3GTPVhf
🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
www.audibletrial.com/johnclean...
🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
bit.ly/3QPNGko
📹Phone I use for recording:
amzn.to/3HepYJu
🎙️Microphone I use (classy, I know):
amzn.to/3AYGdbz
Donate with PayPal (Thank you so much!)
www.paypal.com/donate/?hosted...
☕Complete Java course:
codingwithjohn.thinkific.com/...
codingwithjohn.com

Пікірлер: 343
@prototype0277
@prototype0277 2 жыл бұрын
I've been working with Java for nearly 15 years now. I remember studying linked list in and various other data structures in college. John, you explained something that college professors flunked folks over so much better and in a matter of minutes rather than days. Bravo sir.
@findlestick
@findlestick 2 жыл бұрын
Your channel is the only one that has increased my enthusiasm for Java, tenfold. Your videos really are a breath of fresh air here on KZbin. I’m going to watch all your vids and thumb-them-up in gratitude. 👍
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Awesome, I'm really glad I could inspire that kind of interest!
@usernameusernameusername9835
@usernameusernameusername9835 Жыл бұрын
I love your videos!
@MarkSmith-vo1vn
@MarkSmith-vo1vn Жыл бұрын
@@CodingWithJohn Could you do a Hashset video by chance.
@CodingWithJohn
@CodingWithJohn Жыл бұрын
Great idea! I'm actually planning that for my very next video.
@pequetreques
@pequetreques Жыл бұрын
I was about to post this: "Many tutorials here on KZbin, and on Udemy, etc. But this is the very first time I feel utterly comfortable with one of them, because you go straight to the point in a very clear way, avoiding extra explanations. Thanks for your time/work!". But @findlestick already put a good one, so mine replying his. Thanks again John, you definitely rule this thing. ❤
@jam-yh9il
@jam-yh9il 2 жыл бұрын
I don't know how your videos can be so condensed but still thorough. Thanks from all of the Computer Science majors.
@alexanderrizzi8003
@alexanderrizzi8003 2 жыл бұрын
This is *by far* the easiest video to help understand this concept. As a relatively new programmer, I always found it somewhat puzzling to have different implementations of the List interface, but this video clears so many things up and gives actual reasons for their existence! Cheers!
@goerekt
@goerekt Жыл бұрын
I once had a job to improve performance of a java application. Best improvement was done by just exchange a LinkedList to an ArrayList, because it was used to read a lot by index. Very simple change, but massive impact.
@DassVeryGood
@DassVeryGood Жыл бұрын
Crazy how someone can explain all this clearly and simply in 10 minutes. Where my uni would take 2 mins of explaining nothing with a minimalistic slide showing what a linked list looks like. Thank you so much
@Daniel95221
@Daniel95221 2 жыл бұрын
This is like my operating systems course but condensed in the best way. Thanks for the videos! ❤️
@gabenixon6141
@gabenixon6141 Жыл бұрын
July 14, 2022 - Properly learned ArrayList and LinkedList. Thanks John!
@lootster
@lootster 10 ай бұрын
I have problems understanding LinkedList despite reading numerous articles online. Your video is a god's gift!
@nerminkarapandzic5176
@nerminkarapandzic5176 2 жыл бұрын
I just found your channel, this is the second video I'm watching and it has already become my new favorite channel. Good work, keep it up :)
@paulaa5210
@paulaa5210 Ай бұрын
Thank you so much for all these videos! I've been watching them this semester and they have helped tremendously
@Lyosha.
@Lyosha. 2 жыл бұрын
The arrayList does not leave a "space" for the new element in the new array. It instead duplicates all the values from the index into which you want to move the new element into . Those duplicates are positioned one index down from that point (you get one doubled item ) and then that doubled item is replaced with the new one you are moving so the process it's actually longer than what you explained :)
@briangitego
@briangitego 2 жыл бұрын
These are the best Java tutorials that I've found on KZbin and believe me I've looked. Thanks a lot really!!
@MrCosmonaut
@MrCosmonaut 2 жыл бұрын
I'm glad youtube suggested me your channel John. Your videos are truly inspiring, and quite useful for a beginner like me. I want to declare my appreciation for the work you're doing here =) Thank you!
@jerryg2757
@jerryg2757 2 жыл бұрын
You’re great man. Love your enthusiasm for Java. Keep it up!
@muradalnajjar6533
@muradalnajjar6533 Жыл бұрын
Thank you very much, John! Your way of explaining java concepts is very straightforward to understand. Your videos are worth every second to watch.
@alicewu6674
@alicewu6674 2 жыл бұрын
this is the only video that really makes me understand what an arraylist and linkedlist is, thank you!
@slaki1706
@slaki1706 2 жыл бұрын
Amazingly clear video, great job. Just a minor remark: To emphasize that the interface of the two lists is the same you could have used just List as their type. Generally, that is the recommended way anyway.
@l19870922
@l19870922 2 жыл бұрын
Hi John. Thank you for your wonderful clarification. This is by far the most clear tutorial I have ever watched to understand the difference LinkedList vs ArrayList and you explained it in a perfect way so that I could easily understand it without even re-watch the video.
@bekbolots9634
@bekbolots9634 Жыл бұрын
How can a man be so precise with his teaching! Great job.
@ayushgupta8239
@ayushgupta8239 2 жыл бұрын
Wish i had someone to teach me these stuff earlier…I had to learn these things the hard way. Awesome video man!! Just one thing I think array list uses a load factor of (0.75) to decide when to scale up not when the list is totally full(e.g. like reached 10)
@denniskim4326
@denniskim4326 6 ай бұрын
Thank you for your videos. Trying to learn Java on the job and your tutorials are quite literally saving me at every turn.
@YushinWE
@YushinWE 7 ай бұрын
Wow. What an easy-to-understand yet well-informed video. This is much better than my professor's two-hour lecture on this subject. This is exactly what I want to watch for learning anything!
@davishilton4754
@davishilton4754 Жыл бұрын
You explain things so clearly, keep up the good work and Thanks!!!
@ginandi1
@ginandi1 2 жыл бұрын
In most use cases, amortized analysis shows equivalence of run time. Linked lists, however, lead to more cache misses (array can be bulk copied to cache with much fewer misses) which puts array in a huge advantage for practical reasons as well.
@franfonse
@franfonse 2 жыл бұрын
John. I'm computer engineer student, and your videos are just brilliant. Thank you so much for so, so good content. Keep it up! I will support this channel the best way I can :-)
@jeeperscreepers7
@jeeperscreepers7 2 жыл бұрын
Love your videos! been watching all of them to get prepared for my next job interview :P
@emiliasavin6484
@emiliasavin6484 2 жыл бұрын
Love your videos, short and informative 👍
@omarnoor4249
@omarnoor4249 2 жыл бұрын
Thanks for your tutorial they are helping me a lot in my Java studies. You are a genius.
@wickedsnuk3812
@wickedsnuk3812 2 жыл бұрын
It was like those lectures where the instructor teaches so smoothly so s/he puts everything in your mind without you noticing.
@Hugos68
@Hugos68 2 жыл бұрын
Thank you for the comprehensive video with plenty of examples and thorough explanation!
@antonsilta7248
@antonsilta7248 2 жыл бұрын
Thanks a lot, barely could be clearer! Interesting as hell, can't stop watching :)
@aco7992
@aco7992 2 жыл бұрын
Thanks for clear explanations. I exactly found out what I am looking for.
@prathapvideo
@prathapvideo 2 жыл бұрын
Hey John. I was cording for past 10 years. Never ever thought about it. You are an eye opener. Wonderful explanation. Thank youuuuuu veryyyyyyy muchhhhh😄😄😄😄😄👍👍👍👍👍
@markbozinovic706
@markbozinovic706 2 жыл бұрын
Thanks John, good starting point for Java Coders in the intermediate stages looking to go advanced and being Java is applicable with mobile apps. Have posted on my twitter, Regards and keep these videos going. Mark
@erezswickley2139
@erezswickley2139 Жыл бұрын
Finally, a clear explanation, Thank you! You definitely earned my subscription.
@will_smith_0073
@will_smith_0073 2 жыл бұрын
You make very understandable videos, keep it up!
@amirulidzham
@amirulidzham 2 жыл бұрын
I learn java since 2014 but now I understand it. Huge thanks
@Hackers16
@Hackers16 2 жыл бұрын
thank you so much for this tutorial. now I know what is really the difference between them. I hope you’ll grow your channel more. Please make a tutorial for Data Structures in Java as well. That would be really helpful
@globalskills2861
@globalskills2861 2 жыл бұрын
Hey John i am from morroco nord of Africa i am beginer in Java i just want to Say you are doing a great work your vidéos helps a lot .
@muhibali205
@muhibali205 6 ай бұрын
That's so cool. Loved your video. You got a sub mate !! 👏👏💖💖
@igorlamoia1540
@igorlamoia1540 2 жыл бұрын
Dude, I love your channel, I hated Java a time ago but I've been working with php (some POO) and I've been opening my mind to Java too, I had to do a Project using Java to my College last month, and you helped me so much with your videos. Now I'm watching every video just because I started to Love it. Thanks Bro! Ps: I'm from Brasil, and my english isn't that good.
@newaccaunt6648
@newaccaunt6648 Жыл бұрын
Thank you very much. Quality of the lesson is really good. You are professional. Keep it doing! 👍👍👍
@aldotube88
@aldotube88 Жыл бұрын
First time watching your videos, very good explanation at helping me understand this!
@SpooxyCowboy1911
@SpooxyCowboy1911 Жыл бұрын
It’s so refreshing to hear an explanation that doesn’t have a heavy accent. Almost all my professors are hard to understand and it makes it difficult to learn
@muhammed__5
@muhammed__5 5 ай бұрын
Really love it ur videos John!
@UmangMundhara
@UmangMundhara Жыл бұрын
Really appreciate your explanation , it was too clear and these concepts are pretty clear to me now
@kaledbrahmi3442
@kaledbrahmi3442 3 жыл бұрын
Thank you, I was struggling to understand the difference and now is all clear. Btw I like your channel and I wish you to grow because you deserve it.
@CodingWithJohn
@CodingWithJohn 3 жыл бұрын
No problem at all. Thanks for the kind words, and thanks for watching!
@theblindprogrammer
@theblindprogrammer 2 жыл бұрын
ArrayList is really heavily used in Android as well.
@IbytheGOAT
@IbytheGOAT 11 ай бұрын
I make sure to search your name for any Java concept I gotta learn, you explain things perfectly
@Nitrev
@Nitrev Ай бұрын
Im new to Java and started self-studying. This is so easy to understand thank you
@Jtube0101Mega
@Jtube0101Mega Жыл бұрын
Great lesson! Thank you very much!
@asherkhan2656
@asherkhan2656 11 ай бұрын
Great explanation and good review for me…thank you
@marionthenault8670
@marionthenault8670 8 ай бұрын
This is so clear and so helpful, thank you
@Leandro-zo4kp
@Leandro-zo4kp 2 жыл бұрын
Thank you very much for the content!! Your teaching is great!! Gratitude
@dypsking3414
@dypsking3414 2 жыл бұрын
Super clean & neat explanation 💕
@joannecarrig384
@joannecarrig384 Жыл бұрын
Thank you so much. Your videos are great and really easy to understand.
@JbizzyLoL
@JbizzyLoL 7 ай бұрын
Just want to show appreciation for these videos. You're saving me from drowning in my programming & methodologies II course!!
@onkarjadhav4186
@onkarjadhav4186 2 жыл бұрын
I have watched lots of video for understanding ArrayList and LinkedList difference but this video fix my all doubts.
@balag3611
@balag3611 Жыл бұрын
Ur explanation way are such incredible.Thank you bro . Definitely your channel will 1M subscribtion in the future....Can u say what type IDE r u using
@sarahjuliana7683
@sarahjuliana7683 Жыл бұрын
John, you are awesome. Thank you for your work !
@koksalocal7153
@koksalocal7153 Жыл бұрын
Thank you john for your precious informations and waiting for the next ones😊
@darthnihiluz5305
@darthnihiluz5305 2 жыл бұрын
As of late I've been getting into Java functional/lambda/reactive programming. Definitely took a little bit to get use to, maybe do a series on it?
@sardorruziyev6919
@sardorruziyev6919 Жыл бұрын
Thank you John, very much appreciated!
@panditfamily4202
@panditfamily4202 2 жыл бұрын
Superbly explained 😍....just awesome 👍
@HarshSharma-pk6co
@HarshSharma-pk6co Жыл бұрын
Thank you so much for explanation, i am us array list most of time. But i had read it multiple time but didn't understood it well. But in your end of the video when you gave example that made me understood. Now i know which to use when
@dd8601
@dd8601 Жыл бұрын
Great explanation.thank you so much
@fcbarcatv-ou4ww
@fcbarcatv-ou4ww Жыл бұрын
i have so much respect for you good sir. you are carrying my revisions
@philippecourtemanche7667
@philippecourtemanche7667 Ай бұрын
great explanation Thanks John
@mahmad9095
@mahmad9095 2 жыл бұрын
Thanks for the awesome video. I had bought some Java course on Udemy and I keep coming to your videos as you explain them in a much better way than those in Udemy.
@hyzer.flipr0
@hyzer.flipr0 Жыл бұрын
This was an excellent video. Thank you.
@mdzaidsiddiqui4262
@mdzaidsiddiqui4262 Жыл бұрын
Loved the explanation! (And the Beatles) A channel worth subscribing.
10 ай бұрын
Your channel is amazing!
@RonanClancy
@RonanClancy 2 жыл бұрын
Excellent! Great explanation! Thanks
@Halilbayrak9191
@Halilbayrak9191 2 жыл бұрын
Thank you very much ,it is very clear !!
@MrAikien
@MrAikien Жыл бұрын
Great video! 👌👍 Thanks! 🙏
@DavidMerinos
@DavidMerinos 2 жыл бұрын
This is applyable to C/C++ too and is usually an interview questiton (differences between Array and Linked lists)
@forbidden-cyrillic-handle
@forbidden-cyrillic-handle Жыл бұрын
Oh, wow. Here they usually go asking about very specific and obscure algorithm that you have only 0.001% chance to know. And if you happen to know the answer and get the job, you later realize that specific algorithm is never used in their projects.
@wristdisabledwriter2893
@wristdisabledwriter2893 3 жыл бұрын
Perfect timing I meant to ask you for this
@AbdullohHamidullayev-qm3ls
@AbdullohHamidullayev-qm3ls 2 ай бұрын
thank you so much for your lessons
@noteuser15
@noteuser15 Жыл бұрын
Bro, you are helping me a lot! I am falling way behind in my Java class, and my teacher is not helping me. Your videos are a boon! thanks
@fc6827
@fc6827 9 ай бұрын
Good video, never really thought about this, and have been doing this for 7 years now
@LuisAguilar-hp3lq
@LuisAguilar-hp3lq 2 жыл бұрын
Loved your explanation
@TheCanuckman75
@TheCanuckman75 2 жыл бұрын
Wow this channel is amazing. Subscribed! I have an interview tomorrow, and will definitely be using your videos to learn Java if it doesn’t go well!
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Hope it goes well! And also hope you come back to learn more even if it does go well 😀
@TheCanuckman75
@TheCanuckman75 2 жыл бұрын
@@CodingWithJohn will definitely use your channel to learn!
@TheCanuckman75
@TheCanuckman75 2 жыл бұрын
@@CodingWithJohn I think it went well!! Will probably hear back some time next week! Thank you again!
@danielcisa107
@danielcisa107 2 жыл бұрын
Really like your vids and the way you explain.. Gj
@flytoinfinityvivi
@flytoinfinityvivi Ай бұрын
This is the most amazing course ever! Exactly what I want to know regarding of why use one from the other. Best examples and I got it rightaway. This guy is genius and should be a professor instead.
@Sear-hh4gf
@Sear-hh4gf 2 жыл бұрын
You’re awesome John, thank you!
@fcoGaz
@fcoGaz Жыл бұрын
Thnaks for yours Videos, are Great...regards from Mexico.
@sekharreddy3236
@sekharreddy3236 2 жыл бұрын
You are awesome sir, appreciate your detailed explanation
@rahulbhagwat2182
@rahulbhagwat2182 11 ай бұрын
This is the guy that makes life easy when it comes to Java .....Beautiful explanation 😄
@jordanmcguire2344
@jordanmcguire2344 2 жыл бұрын
Thank you so much. I am glad I watched this.
@tian_wijaya
@tian_wijaya Жыл бұрын
great explanation, thank you
@Zalaniar
@Zalaniar Жыл бұрын
Great video! I've actually never used either of these collections, as my java teacher had a preference for Vector and it stuck with me. So that leads me to a question: how do Vector and other collection classes play into the discussion and when would you use them over ArrayList?
@DavisTibbz
@DavisTibbz 7 ай бұрын
Vectors are no longer recomnended in Java, old, and poor performance. According to java official documentation, avoid it
@bambangariyanto2306
@bambangariyanto2306 2 жыл бұрын
i love Java, so sad some programmers are leaving it.. but i am glad, someone like you learn a java.
@Anonymous-ot2kk
@Anonymous-ot2kk 7 ай бұрын
Thanks for this video 🙏
@atulaggarwal2897
@atulaggarwal2897 2 жыл бұрын
Please provide more information on time complexity of operations in case of ArrayList and LinkedList
@bradcabbage5132
@bradcabbage5132 2 жыл бұрын
i love you john ur keeping me hungry for more knowledge
@badwrong
@badwrong 2 жыл бұрын
The traversal of a linked-list is slower than shifting all the elements of an array list by one. So, with larger amounts of data modifying a linked-list becomes exponentially slower and produces many cache misses.
@jvsnyc
@jvsnyc 2 жыл бұрын
ArrayList is still great if you are adding tons of stuff only to the end. It only needs to move stuff over when adding *not* at the end, otherwise it just places the element at the end and updates the current size. Additionally, it only needs to create a new array and copy everything over when the reserved capacity is exhausted. If you are keeping a reference to some node deep in the midst of the LinkedList, and adding or removing around *that*, then the LinkedList is faster. Also, if for some reason you are often adding and removing right at the beginning, a LinkedList comes into its own. Lastly, there is more memory overhead and less cache coherence with LinkedList. A funny quote I remember: “Does anyone actually use LinkedList? I wrote it, and I never use it.” Joshua Bloch Searching that gives some interesting information on it. As you said tho, for small data sizes, either of them would work great, you will likely never notice a difference unless your data gets larger.
@DanielNit
@DanielNit 2 жыл бұрын
I use LinkedLists a lot for exactly the memory reason. Namely no memory fragmentation. Where an ArrayList occupies new bigger and bigger chunks as it grows, it leaves the old memory segments behind that are too small for the new List to fit into. Thus memory will easily look like swiss cheese with lots of unuseable free memory inbetween. The LinkedLust however can place its nodes into "any tiny spot" and thus saturate memory more dynamically. So while a LL sure performs worse as a main read-object, the write-benefits outweigh for temporary and dynamic data in my opinion.
@jvsnyc
@jvsnyc 2 жыл бұрын
@@DanielNit what you describe can be true in some circumstances, I believe it is less relevant in garbage collected systems with a mature and evolved collector. That is, the jvm has freedom to do a lot of heap cleanup behind the scenes. It was relevant in c and c++ for me however. If you are often adding or removing far from the ends the linked list is great. Arraydeque comes into its own when all or most of the adds and removes are at or near either or both ends. For small data, none of this makes much difference. For larger data profiling one's heap interactions can answer the question for the actual combination of data, code and jvm/gc implementation.
@DanielNit
@DanielNit 2 жыл бұрын
Sure in managed languages like Java, it likely wont have that much of an impact, but as most things, it is situational. Henve why I specifically refered to dynamic and temporary use cases and it all surely only matters at bigger sizes. So tens of thousands, millions and more, as well as services/servers that continously run for a long time. That said, I didnt doubt your expertise or anything but it is merely my quirk with fragmentations from many languages with absolutely no solutions against these issues but similar data structures as described in this video. Also happy new yeah ^_^
@jvsnyc
@jvsnyc 2 жыл бұрын
@@DanielNit you too. Fragmentation is a huge issue in non-managed systems if ignored. Large commercial systems I worked on addressed it on at least two levels and it was still something to consider even then. I have spent less time so far monitoring pure Java systems, and gc is one area that may change and evolve more as it doesn't affect the api's. Happy new year!
@schwingedeshaehers
@schwingedeshaehers 2 жыл бұрын
@@DanielNit if there is place behind the current array, it should expend in that, and don't take a new place. Else the question is, if the overhead of the linked list is worth it, to not take a chunk of memory. (Together with the get time complexity)
@nicholaswhite7351
@nicholaswhite7351 2 ай бұрын
Thank you for you work.
@JonasKeil
@JonasKeil 2 жыл бұрын
This video is great!! 🎉
@elixerprince_art
@elixerprince_art 6 ай бұрын
You my good sir are a great Java teacher!
Set and HashSet in Java - Full Tutorial
20:43
Coding with John
Рет қаралды 193 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 490 М.
Who’s more flexible:💖 or 💚? @milanaroller
00:14
Diana Belitskay
Рет қаралды 17 МЛН
Чай будешь? #чайбудешь
00:14
ПАРОДИИ НА ИЗВЕСТНЫЕ ТРЕКИ
Рет қаралды 2 МЛН
Learn Linked Lists in 13 minutes 🔗
13:24
Bro Code
Рет қаралды 252 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1 МЛН
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 699 М.
Redis Crash Course
27:31
Web Dev Simplified
Рет қаралды 593 М.
Map and HashMap in Java - Full Tutorial
10:10
Coding with John
Рет қаралды 532 М.
14.5 LinkedList vs ArrayList in Java
9:16
Telusko
Рет қаралды 403 М.
Who’s more flexible:💖 or 💚? @milanaroller
00:14
Diana Belitskay
Рет қаралды 17 МЛН