In an array, memory is assigned during compile time while in a Linked list it is allocated during execution or runtime.In contrast, Linked lists are dynamic and flexible and can expand and contract its size. On the other hand, the performance of these operations in Linked lists is fast. Operations like insertion and deletion in arrays consume a lot of time.While accessing an element array is fast while Linked list takes linear time so, it is quite bit slower.In a linked list though, you have to start from the head and work your way through until you get to the fourth element. In the array the elements belong to indexes, i.e., if you want to get into the fourth element you have to write the variable name with its index or location within the square bracket.An array is the data structure contains a collection of similar type data elements whereas the Linked list is considered as non-primitive data structure contains a collection of unordered linked elements known as nodes.Key Differences Between Array and Linked List Printf ("Do you want to continue (type y or n) ? \n") If we read the one-dimensional array, it requires one loop for reading and other for writing (printing) the array, for example: Arrays can be read or written through the loop.Where 0 is the lower bound of the array, and 9 is the upper bound of the array. The number of elements that can be stored in an array, i.e., the size of an array or its length is given by the following equation:įor the above array, it would be (9-0) + 1 =10.It means the first and last element will be specified as a, and a respectively. The very first element of the array has index zero.In any case the elements of an array will be stored in a consecutive memory location.For example, to retrieve 5th element of the array, we need to write a statement a. The individual elements of an array can be accessed by describing the name of the array, followed by index or subscript (determining the location of the element in the array) inside the square brackets.Let us look at some of the concepts to be remembered about arrays: “a” is the name of an array, and the number specified inside the square brackets is the number of elements an array can store, this is also called size or length of the array. Where int specifies the data type or type elements array stores. It means an array can contain one type of data only, either all integers, all floating-point numbers, or all characters. Sequentially accessed, i.e., Traverse starting from the first node in the list by the pointer.Īn array is defined as a set of a definite number of homogeneous elements or data items. No need to specify grow and shrink during execution.Įlement location is allocated during compile time.Įlement position is assigned during run time.ĭirect or randomly accessed, i.e., Specify the array index or subscript. It is an ordered set comprising a variable number of data items. It is a consistent set of a fixed number of data items. The address used to access a particular node is known as a pointer.Īnother significant difference between an array and linked list is that Array has a fixed size and required to be declared prior, but Linked List is not restricted to size and expand and contract during execution. Furthermore, the link field holds the address of the next data item in the linked list. One is Data field, and other is link field, Data field contains the actual value to be stored and processed. There are two fields in an element of linked list. While a linked list is a data structure which contains a sequence of the elements where each element is linked to its next element. Basically, an array is a set of similar data objects stored in sequential memory locations under a common heading or a variable name. “ Returns the specified fromIndex}( contain ) and toIndex}( exclude ) Between the list parts of the view. “ Returns a view of the portion of this list between the specified fromIndex}, inclusive, and toIndex}, exclusive. 2.5 Cause analysisįirst, Let's take a look at subList Method comments, Find out what it does : It can be seen that, When we add elements to a subset ( Structural modification ) after, It affects the original set bookList. LuyaoBookList.add(" The morning begins at noon ") List luyaoBookList = bookList.subList(3, 5) Such as, Let's go to the subset luyaoBookList Add an element to ( Structural modification ): List bookList = new ArrayList() 2.4 Modify the structure of the subset, Will affect the original set It can be seen that, Although we only modified the subset luyaoBookList Value, But it affects the original set bookList.