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

  Рет қаралды 607,777

Coding with John

Coding with John

Күн бұрын

Пікірлер: 367
@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.
@jorgeburgos6502
@jorgeburgos6502 Ай бұрын
I´m currently struggling through my data structures course and i couldn´t agree more. My professor has spent the last 4 classess explaining this topic to us and i honestly couldn´t get it because my adhd doesn´t let me pay attention for more than a minute after I get ever so slightly lost; but all i needed was John´s explanation about how both are dynamic arrays that only differ in the way tey access the nodes.
@gerardonavarro3400
@gerardonavarro3400 Ай бұрын
​@@jorgeburgos6502well, normally ik a data structures class you would learn to implement it by yourself, not just import it from the utils package, but you got most of the idea through so keep it up
@phinhhung2398
@phinhhung2398 2 ай бұрын
Conclusion, AL is better for storing, retrieving and displaying data, LL is better for manipulate (add, insert or remove).
@findlestick
@findlestick 3 жыл бұрын
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 3 жыл бұрын
Awesome, I'm really glad I could inspire that kind of interest!
@usernameusernameusername9835
@usernameusernameusername9835 2 жыл бұрын
I love your videos!
@MarkSmith-vo1vn
@MarkSmith-vo1vn 2 жыл бұрын
@@CodingWithJohn Could you do a Hashset video by chance.
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
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. ❤
@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.
@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.
@nootwin5602
@nootwin5602 Жыл бұрын
Ngl I would die without this channel
@gabenixon6141
@gabenixon6141 2 жыл бұрын
July 14, 2022 - Properly learned ArrayList and LinkedList. Thanks John!
@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 :)
@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.
@lootster
@lootster Жыл бұрын
I have problems understanding LinkedList despite reading numerous articles online. Your video is a god's gift!
@dedz
@dedz 2 жыл бұрын
If someone is wondering why arrays have a constant time to get an element, it's because to get an element from the array, it makes a calculation, a really simple calculation actually.. the programs already knows the position that the array is located in the memory, and already knows the type of data the array is holding, so it can calculate the location of any index with a constant number of steps by doing : memoryPosition + (index * typeSize). So, knowing the “start” position of the array, you just need to multiply the index by the amount of memory that this specific type takes. Let’s say you have an array that holds 100 int numbers, and let’s say the array is located at the space 1000 of the memory.. and int numbers take 4 bytes of memory each. So, to get the 50th element, we just need to multiply the index by the size of bytes (49 * 4) and we will get 196 bytes, now, just add the 1000 (the position that the array starts in the memory), you will get 1196 bytes, this is where the index number 49 is located. That's why it's constant, because you can have a 3 size array or a 100000 size array, the array will always do the same math calculation to get the index that you want to get.
@SpooxyCowboy1911
@SpooxyCowboy1911 2 жыл бұрын
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
@DassVeryGood
@DassVeryGood 2 жыл бұрын
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
@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.
@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!
@ryuujisan32codes
@ryuujisan32codes 4 ай бұрын
As someone who hasn't touched java except when an interview required it - watching your videos made me feel like I can code anything in java now. You're an excellent teach, bro. You've got a gift for sure.
@amirulidzham
@amirulidzham 2 жыл бұрын
I learn java since 2014 but now I understand it. Huge 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.
@jvsnyc
@jvsnyc 3 жыл бұрын
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)
@Nitrev
@Nitrev 6 ай бұрын
Im new to Java and started self-studying. This is so easy to understand thank you
@bekbolots9634
@bekbolots9634 Жыл бұрын
How can a man be so precise with his teaching! Great job.
@SwinkMediaHouse
@SwinkMediaHouse Ай бұрын
Great vid... the more I learn about Java the more these tutorials come through in the clutch.
@ljka
@ljka 2 жыл бұрын
ArrayList: if your logic GET value frequently LinkedList: if your logic INSERTS/ADDS, DELETE value frequently Thanks for video! Im learning a lot. My goal for #2022 is Spring Certification and Java Certification.
@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 .
@tonystark6215
@tonystark6215 5 ай бұрын
Array list - retrieval Linked list - insertion, deletion
@itsAfantasyName
@itsAfantasyName 2 жыл бұрын
As a non-native speaker and java beginner I recommend switching the audio pace to 0.75 ;D otherwise great explanation!
@bambangariyanto2306
@bambangariyanto2306 2 жыл бұрын
i love Java, so sad some programmers are leaving it.. but i am glad, someone like you learn a java.
@onkarjadhav4186
@onkarjadhav4186 3 жыл бұрын
I have watched lots of video for understanding ArrayList and LinkedList difference but this video fix my all doubts.
@alicewu6674
@alicewu6674 2 жыл бұрын
this is the only video that really makes me understand what an arraylist and linkedlist is, thank you!
@JbizzyLoL
@JbizzyLoL Жыл бұрын
Just want to show appreciation for these videos. You're saving me from drowning in my programming & methodologies II course!!
@YushinWE
@YushinWE Жыл бұрын
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!
@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!!
@DavidMerinos
@DavidMerinos 2 жыл бұрын
This is applyable to C/C++ too and is usually an interview questiton (differences between Array and Linked lists)
@inchworm9311
@inchworm9311 2 жыл бұрын
Thank you. ArrayList = searching LinkedList = adding/removing
@CodingWithJohn
@CodingWithJohn 2 жыл бұрын
Be sure to check out the pinned comment - ArrayList tends to be faster for literally everything 99% of the time due to modern architecture, even though theoretically it might seem that LinkedList should be faster for some operations.
@IbytheGOAT
@IbytheGOAT Жыл бұрын
I make sure to search your name for any Java concept I gotta learn, you explain things perfectly
@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 Жыл бұрын
Thank you for your videos. Trying to learn Java on the job and your tutorials are quite literally saving me at every turn.
@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.
@rahulbhagwat2182
@rahulbhagwat2182 Жыл бұрын
This is the guy that makes life easy when it comes to Java .....Beautiful explanation 😄
@flytoinfinityvivi
@flytoinfinityvivi 7 ай бұрын
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.
@nataliabrahamyan7880
@nataliabrahamyan7880 Жыл бұрын
please please please dedicate an entire video to only LinekdLists and the Node class I am struggling with my midterm!!
@paulaa5210
@paulaa5210 7 ай бұрын
Thank you so much for all these videos! I've been watching them this semester and they have helped tremendously
@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😄😄😄😄😄👍👍👍👍👍
@harshavardhan3133
@harshavardhan3133 2 жыл бұрын
ArrayList allocates size in powers of 2 , it would need to find a new bigger array only when the limit exceeds the powers of 2, the capacity is the allocated size of arraylist, So insertion is relatively more efficient 😅, but the LinkedList is memory efficient.
@r_s_steam_cr
@r_s_steam_cr Ай бұрын
La mejor explicación del mundo mundial! Gracias!
@ayseklnc1650
@ayseklnc1650 10 ай бұрын
farklı bir dilde olmasına rağmen çok başarılı bir anlatımınız var ,tebrikler
@wesleyalencarsouza254
@wesleyalencarsouza254 2 жыл бұрын
Resumo: LinkedList -> lista encadeada de crescimento dinâmico. ArrayList -> lista com vetor estático que dobra de tamanho quando o limite dele é atingido, e isso dá a impressão que também é dinâmico.
@virgo47
@virgo47 2 жыл бұрын
I'm glad there is that pinned comment. The video is technically (videographically) fine, but the content is really questionable. I'd also type the variables as List, it is universally good practice, unless you want to use specific methods (e.g. queue operations). And then there is that LinkedList theoretical usefulness: 1) One big trouble is that having an element and getting the internal list node are two different things. So in theory, remove is O(1) if you have the node. But you don't, so in practice it's O(N). 2) While going linearly through a list and then quickly removing a single element MIGHT be still faster than shifting stuff in an array, it hardly ever is because of memory co-location of array list elements (and lack thereof in linked list). Many array list operations are covered by the fastest caches in CPU, while the linked list jumps often all over the place evicting cache rows in the process. Long story short, array list virtually for all cases. Linked list perhaps for some queue/stack tasks, unless you use something even better suited from other libraries. And measure before bold claims.
@jelmerterburg3588
@jelmerterburg3588 2 жыл бұрын
For queues and stacks, ArrayDeque is a similarly superior substitute for LinkedList :).
@noteuser15
@noteuser15 2 жыл бұрын
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
@omarnoor4249
@omarnoor4249 2 жыл бұрын
Thanks for your tutorial they are helping me a lot in my Java studies. You are a genius.
@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.
@giluy87
@giluy87 2 жыл бұрын
I'd say the main difference is that LinkedList also implements Queue interface
@wristdisabledwriter2893
@wristdisabledwriter2893 3 жыл бұрын
Perfect timing I meant to ask you for this
@HarshSharma-pk6co
@HarshSharma-pk6co 2 жыл бұрын
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
@tales_
@tales_ 2 жыл бұрын
Array list faster random access, slower adding/editing Linked list slower accessing if index is higher, faster adding/editing
@erezswickley2139
@erezswickley2139 2 жыл бұрын
Finally, a clear explanation, Thank you! You definitely earned my subscription.
@fc6827
@fc6827 Жыл бұрын
Good video, never really thought about this, and have been doing this for 7 years now
@newaccaunt6648
@newaccaunt6648 Жыл бұрын
Thank you very much. Quality of the lesson is really good. You are professional. Keep it doing! 👍👍👍
@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 :)
@aco7992
@aco7992 2 жыл бұрын
Thanks for clear explanations. I exactly found out what I am looking for.
@ivankobyuk8385
@ivankobyuk8385 2 жыл бұрын
Huge thanks from Ukrainian developer!) / Дякую від українського розробника!)
@Hugos68
@Hugos68 2 жыл бұрын
Thank you for the comprehensive video with plenty of examples and thorough explanation!
@marionthenault8670
@marionthenault8670 Жыл бұрын
This is so clear and so helpful, thank you
@murad_alnajjar
@murad_alnajjar 2 жыл бұрын
Thank you very much, John! Your way of explaining java concepts is very straightforward to understand. Your videos are worth every second to watch.
@cool-aquarian
@cool-aquarian 8 сағат бұрын
Which is faster? Getting elements position 0 to 100 in arraylist vs same 0 to 100 in linkedlist ?
@elixerprince_art
@elixerprince_art Жыл бұрын
You my good sir are a great Java teacher!
@jeeperscreepers7
@jeeperscreepers7 2 жыл бұрын
Love your videos! been watching all of them to get prepared for my next job interview :P
@SushiRicetm
@SushiRicetm 2 жыл бұрын
John single handedly carrying me thru cs class
@aldotube88
@aldotube88 Жыл бұрын
First time watching your videos, very good explanation at helping me understand this!
@davishilton4754
@davishilton4754 Жыл бұрын
You explain things so clearly, keep up the good work and Thanks!!!
@Daniel95221
@Daniel95221 3 жыл бұрын
This is like my operating systems course but condensed in the best way. Thanks for the videos! ❤️
@BakhtyarQadri
@BakhtyarQadri 5 ай бұрын
Inshort, LinkedList is way better than ArrayList (totally unexpected for me), if memory is not an issue.
@JonasKeil
@JonasKeil 2 жыл бұрын
This video is great!! 🎉
@isho7777
@isho7777 2 жыл бұрын
Finally someone i can understand. finally someone who dont speak mumble and greek language combined
@fcbarcatv-ou4ww
@fcbarcatv-ou4ww Жыл бұрын
i have so much respect for you good sir. you are carrying my revisions
@antonsilta7248
@antonsilta7248 2 жыл бұрын
Thanks a lot, barely could be clearer! Interesting as hell, can't stop watching :)
@joannecarrig384
@joannecarrig384 Жыл бұрын
Thank you so much. Your videos are great and really easy to understand.
@PyradonisFootball
@PyradonisFootball Жыл бұрын
Amazing explanation, thank you
@sardorruziyev6919
@sardorruziyev6919 2 жыл бұрын
Thank you John, very much appreciated!
@thanhlongo1843
@thanhlongo1843 2 жыл бұрын
Mình chắc chắn nếu có phụ đề tiếng việt thì sẽ có rất nhiều view, mình mong chờ nó, cảm ơn nhiều
@LizyAd
@LizyAd 2 ай бұрын
Thank you so much! Such a clear explanation!!
@Jtube0101Mega
@Jtube0101Mega 2 жыл бұрын
Great lesson! Thank you very much!
@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 :-)
@lunarieu4815
@lunarieu4815 Жыл бұрын
John thanks a million for your videos, can you do a video comparing Singly Linked List vs Doubly Linked List ? thanks a million!
@IToucann
@IToucann 7 ай бұрын
John is truly insane! Well explained!
@gabrielcifuentes916
@gabrielcifuentes916 2 жыл бұрын
i remember when i was in my degree on structure topic, we learned linked list, double linkdlist an so on. Great times
@asherkhan2656
@asherkhan2656 Жыл бұрын
Great explanation and good review for me…thank you
@koksalocal7153
@koksalocal7153 Жыл бұрын
Thank you john for your precious informations and waiting for the next ones😊
@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 3 жыл бұрын
ArrayList is really heavily used in Android as well.
@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.
@bradcabbage5132
@bradcabbage5132 2 жыл бұрын
i love you john ur keeping me hungry for more knowledge
@stefans6557
@stefans6557 2 жыл бұрын
What is the difference to: List namesArrayList = new ArrayList(); (and the same for LinkedList?)
@atulaggarwal2897
@atulaggarwal2897 2 жыл бұрын
Please provide more information on time complexity of operations in case of ArrayList and LinkedList
@dd8601
@dd8601 Жыл бұрын
Great explanation.thank you so much
@jerryg2757
@jerryg2757 3 жыл бұрын
You’re great man. Love your enthusiasm for Java. Keep it up!
@hamza-hx3by
@hamza-hx3by Ай бұрын
Thank you so much for sharing these courses with us. I have a question, when we add many objects to an ArrayList we know that it creates a larger internal list each time it runs out of space so, What happens to the previous internal lists that The ArrayList created before the latest one? Ones again Thank you very much john, hope you can share your LinkedIn Account with Us : ) !
@sarahjuliana7683
@sarahjuliana7683 Жыл бұрын
John, you are awesome. Thank you for your work !
@bwprogrammers874
@bwprogrammers874 3 жыл бұрын
You are the best Sir...
@balag3611
@balag3611 2 жыл бұрын
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
@emiliasavin6484
@emiliasavin6484 2 жыл бұрын
Love your videos, short and informative 👍
Set and HashSet in Java - Full Tutorial
20:43
Coding with John
Рет қаралды 232 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 553 М.
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 13 МЛН
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 2,9 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 10 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 94 МЛН
Learn Linked Lists in 13 minutes 🔗
13:24
Bro Code
Рет қаралды 347 М.
14.5 LinkedList vs ArrayList in Java
9:16
Telusko
Рет қаралды 413 М.
Linked Lists for Technical Interviews - Full Course
1:27:24
freeCodeCamp.org
Рет қаралды 366 М.
Map and HashMap in Java - Full Tutorial
10:10
Coding with John
Рет қаралды 602 М.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 769 М.
Introduction to Linked Lists (Data Structures & Algorithms #5)
18:47
Vectors in Java: The 1 Situation You Might Want To Use Them
16:13
Coding with John
Рет қаралды 84 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1,1 МЛН
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 13 МЛН