Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an array and a list

Tags:

arrays

swift

I was wandering around in stack overflow for questions when i saw that some people used arrays and others used lists and i was wondering what is the difference between list and arrays.

like image 830
Dordor Avatar asked Mar 25 '26 05:03

Dordor


1 Answers

The over simplified answer is that arrays contain data in contiguous space in memory and lists generally store their information in non-contiguous space. In an array you know what the next data element is by moving down to the next element like moving to the house next door on a street. It's the physical displacement across a standard size memory boundary that lets you find the next element.

In an "list" each element in the list keeps a "pointer" to the location of the next element in the list. So in an array you can jump to the 5th element just as you can walk straight to the fifth house on a street. In a list you'd have to knock on each house's door and ask inside what the address of the next house in the group (i.e. list) is. That next house could be anywhere in the city.

like image 128
mba12 Avatar answered Mar 28 '26 03:03

mba12



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!